Skip to content

Instantly share code, notes, and snippets.

@RobertCodez
Created July 30, 2021 16:59
Show Gist options
  • Save RobertCodez/670c23f346a5f01db7d1a752da4a9c39 to your computer and use it in GitHub Desktop.
Save RobertCodez/670c23f346a5f01db7d1a752da4a9c39 to your computer and use it in GitHub Desktop.
Pet Hatching, and Chicken fighting in Arena's
local plr = game.Players.LocalPlayer
local cam = workspace.CurrentCamera
local TS = game:GetService("TweenService")
local arenaInstructions = {"Welcome to the Wide Arena!", "Your chickens will battle against everybody else's Chicken!", "The winner will win a prize of 500 Coins!", "May the best Chicken win!"}
local impossible = false
local function cameraShake()
for i = 1, 20 do
local x = math.random(-10,10)/100
local y = math.random(-10,10)/100
local z = math.random(-10,10)/100
plr.Character.Humanoid.CameraOffset = Vector3.new(x,y,z)
wait()
end
end
local function cameraRotate(part)
cam.CameraType = Enum.CameraType.Scriptable
local c = 0
rotateCamera = game:GetService("RunService").Heartbeat:Connect(function()
local cframe = part.CFrame * CFrame.Angles(0, math.rad(c), 0) * CFrame.new(0, 0, -15)
cframe = CFrame.new(cframe.p, part.Position)
cam.CFrame = cframe
c = c + 3;
end)
end
local function disableAllGui(except)
for _,ui in pairs(plr.PlayerGui:GetChildren()) do
if ui.Name ~= except then
ui.Enabled = false
end
end
end
local function enableAllGui()
for _,ui in pairs(plr.PlayerGui:GetChildren()) do
ui.Enabled = true
end
end
local function stopCameraRotate()
rotateCamera:Disconnect()
cam.CameraType = Enum.CameraType.Custom
cam.CameraSubject = plr.Character.Humanoid
end
local function modifyPlayerControls(bool)
local Controls = require(plr.PlayerScripts.PlayerModule):GetControls()
Controls:Enable(bool)
end
local function resetCamera()
cam.CameraType = Enum.CameraType.Custom
cam.CameraSubject = plr.Character.Humanoid
end
game.ReplicatedStorage.GuiReplicator.OnClientEvent:Connect(function(uiname, info, goal, housemodel)
if plr.PlayerGui:FindFirstChild(uiname) and uiname ~= "AddCash" then return end
if uiname == "StageBuy" then
local UI = game.ReplicatedStorage.Gui[uiname]:Clone()
UI.Parent = plr.PlayerGui
UI.Frame.StageName.Text = info.Type.Value
UI.Frame.Price.Text = info.Price.Value.." Coins"
TS:Create(UI.Frame, TweenInfo.new(1), {Position = UDim2.new(0.354, 0,0.3, 0)}):Play()
UI.Frame.Yes.MouseButton1Down:Connect(function()
local result = game.ReplicatedStorage.BuyStage:InvokeServer(info)
if result then
UI.Frame.Description:Destroy()
UI.Frame.No:Destroy()
UI.Frame.Price.Text = "UNLOCKED STAGE!"
UI.Frame.Yes:Destroy()
wait(1)
TS:Create(UI.Frame, TweenInfo.new(1),{Position = UDim2.new(0.354, 0,-0.9, 0)}):Play()
wait(1)
UI:Destroy()
else
UI.Frame.Description:Destroy()
UI.Frame.No:Destroy()
UI.Frame.Price.TextColor3 = Color3.fromRGB(255, 0, 4)
UI.Frame.Price.Text = "NOT ENOUGH COINS!"
UI.Frame.Yes:Destroy()
wait(1)
TS:Create(UI.Frame, TweenInfo.new(1),{Position = UDim2.new(0.354, 0,-0.9, 0)}):Play()
wait(1)
UI:Destroy()
end
end)
UI.Frame.No.MouseButton1Down:Connect(function()
TS:Create(UI.Frame, TweenInfo.new(1),{Position = UDim2.new(0.354, 0,-0.9, 0)}):Play()
wait(1)
UI:Destroy()
end)
elseif uiname == "ArenaInstructions" then
local UI = game.ReplicatedStorage.Gui[uiname]:Clone()
UI.Parent = plr.PlayerGui
plr.Character:SetPrimaryPartCFrame(workspace.WideArena.Cam4.CFrame)
workspace["Sunny Farm"]:Stop()
game.Lighting.ArenaMusic:Play()
disableAllGui(UI.Name)
cam.CameraType = Enum.CameraType.Scriptable
for index, message in pairs(arenaInstructions) do
pcall(function()
cam.CFrame = workspace.WideArena["Cam"..index].CFrame
end)
UI.Main.DESCRIPTION.Text = message
TS:Create(UI.Main, TweenInfo.new(.3), {Size = UDim2.new(0.32, 0,0.163, 0)}):Play()
wait(7)
TS:Create(UI.Main, TweenInfo.new(.3), {Size = UDim2.new(0.32, 0,0.064, 0)}):Play()
wait(.4)
end
TS:Create(UI.Main, TweenInfo.new(1), {Size = UDim2.new(0.32, 0,0.064, 0)}):Play()
UI:Destroy()
resetCamera()
enableAllGui()
modifyPlayerControls(true)
elseif uiname == "WinnerAnnounce" then
local UI = game.ReplicatedStorage.Gui[uiname]:Clone()
UI.Parent = plr.PlayerGui
disableAllGui(uiname)
pcall(function()
workspace[info].Archivable = true
clone = workspace[info]:Clone()
clone.Parent = workspace
clone.Humanoid:LoadAnimation(game.Lighting.Wave):Play()
clone:SetPrimaryPartCFrame(workspace.WinnerStage.TargetPos.CFrame)
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = workspace.WinnerStage.TargetPos.CFrame * CFrame.new(0, 0, -10)
cam.CFrame = cam.CFrame * CFrame.Angles(0, math.rad(180), 0)
TS:Create(cam, TweenInfo.new(4), {CFrame = cam.CFrame * CFrame.new(0, 0, 5)}):Play()
end)
UI.Main.DESCRIPTION.Text = info.." has won the Wide Arena free for all!"
workspace["Sunny Farm"]:Stop()
game.Lighting.ArenaMusic:Stop()
game.Lighting.ArenaWinner:Play()
TS:Create(UI.Main, TweenInfo.new(2), {Position = UDim2.new(0.34, 0,0.045, 0)}):Play()
wait(15)
pcall(function()
cam.CameraType = Enum.CameraType.Custom
cam.CameraSubject = plr.Character.Humanoid
clone:Destroy()
end)
enableAllGui()
wait(10)
TS:Create(UI.Main, TweenInfo.new(2), {Position = UDim2.new(0.34, 0,1.1, 0)}):Play()
wait(3)
workspace["Sunny Farm"]:Play()
UI:Destroy()
elseif uiname == "ArenaInvitation" then
local UI = game.ReplicatedStorage.Gui[uiname]:Clone()
UI.Parent = plr.PlayerGui
TS:Create(UI.Main, TweenInfo.new(1), {Position = UDim2.new(0.33, 0,0.311, 0)}):Play()
UI.Main.Yes.MouseButton1Down:Connect(function()
game.ReplicatedStorage.JoinArena:InvokeServer()
modifyPlayerControls(false)
TS:Create(UI.Main, TweenInfo.new(1),{Position = UDim2.new(0.33, 0,-0.5, 0)}):Play()
wait(1)
UI:Destroy()
end)
UI.Main.No.MouseButton1Down:Connect(function()
TS:Create(UI.Main, TweenInfo.new(1),{Position = UDim2.new(0.33, 0,-0.5, 0)}):Play()
wait(1)
UI:Destroy()
end)
pcall(function()
wait(7)
TS:Create(UI.Main, TweenInfo.new(1),{Position = UDim2.new(0.33, 0,-0.5, 0)}):Play()
wait(1)
UI:Destroy()
end)
elseif uiname == "BuyChicken" then
local UI = game.ReplicatedStorage.Gui[uiname]:Clone()
UI.Parent = plr.PlayerGui
UI.Frame.StageName.Text = info
UI.Frame.Price.Text = goal.." COINS"
TS:Create(UI.Frame, TweenInfo.new(1), {Position = UDim2.new(0.354, 0,0.3, 0)}):Play()
UI.Frame.Yes.MouseButton1Down:Connect(function()
local result = game.ReplicatedStorage.BuyChicken:InvokeServer()
if result then
UI.Frame.Description:Destroy()
UI.Frame.No:Destroy()
UI.Frame.Price.Text = "BOUGHT CHICKEN!"
UI.Frame.Yes:Destroy()
wait(1)
TS:Create(UI.Frame, TweenInfo.new(1),{Position = UDim2.new(0.354, 0,-0.9, 0)}):Play()
wait(1)
UI:Destroy()
else
UI.Frame.Description:Destroy()
UI.Frame.No:Destroy()
UI.Frame.Price.TextColor3 = Color3.fromRGB(255, 0, 4)
UI.Frame.Price.Text = "NOT ENOUGH COINS!"
UI.Frame.Yes:Destroy()
wait(1)
TS:Create(UI.Frame, TweenInfo.new(1),{Position = UDim2.new(0.354, 0,-0.9, 0)}):Play()
wait(1)
UI:Destroy()
end
end)
UI.Frame.No.MouseButton1Down:Connect(function()
TS:Create(UI.Frame, TweenInfo.new(1),{Position = UDim2.new(0.354, 0,-0.9, 0)}):Play()
wait(1)
UI:Destroy()
end)
elseif uiname == "HatchEggUI" then
local UI = game.ReplicatedStorage.Gui[uiname]:Clone()
local Main = UI.Main
UI.Parent = plr.PlayerGui
UI.Main.Description.Text = "Do you want to hatch a "..info.." Egg?"
UI.Main.Price.Text = goal.." COINS"
TS:Create(UI.Main, TweenInfo.new(1), {Position = UDim2.new(0.303, 0,0.167, 0)}):Play()
Main.No.MouseButton1Click:Connect(function()
TS:Create(UI.Main, TweenInfo.new(1), {Position = UDim2.new(0.303, 0,0.999, 0)}):Play()
wait(1.5)
UI:Destroy()
end)
Main.Yes.MouseButton1Click:Connect(function()
local result = game.ReplicatedStorage.HatchEgg:InvokeServer(info)
if result then
Main.No:Destroy()
Main.Yes:Destroy()
Main.Price:Destroy()
Main.Description.Text = "HATCHING EGG!"
Main.Icon.Rotation = -30
local rotateEgg = TS:Create(Main.Icon, TweenInfo.new(.08,Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 25,true,0), {Rotation = 30})
rotateEgg:Play()
local endLoop = false
rotateEgg.Completed:Connect(function()
endLoop = true
game.Lighting.Success:Play()
Main.Description.Text = result[1]
Main.Description.TextStrokeTransparency = 0
Main.Description.TextColor3 = result[2]
Main.Icon:Destroy()
wait(4)
TS:Create(UI.Main, TweenInfo.new(1),{Position = UDim2.new(0.303, 0,0.999, 0)}):Play()
wait(1)
UI:Destroy()
end)
repeat
game.Lighting.EggBreak:Play()
cameraShake()
wait(.08)
until endLoop
else
Main.Description:Destroy()
Main.No:Destroy()
Main.Price.TextColor3 = Color3.fromRGB(255, 0, 4)
Main.Price.Text = "NOT ENOUGH COINS!"
Main.Yes:Destroy()
wait(1)
TS:Create(UI.Main, TweenInfo.new(1),{Position = UDim2.new(0.303, 0,0.999, 0)}):Play()
wait(1)
UI:Destroy()
end
end)
end
end)
plr.ChildRemoved:Connect(function(child)
if child.Name == "Arena" then
game.Lighting.ArenaMusic:Stop()
workspace["Sunny Farm"]:Play()
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment