Need help with local script

why is this script not working?

local object = script.Parent
local Character = game.Players.LocalPlayer.Character
local CanWin = true
object.AnchorPoint = Vector2.new(.5,.5)
object.Position = UDim2.new(.1,0,.5,0)

wait(1)
object:TweenPosition(UDim2.new(.5,0,.5,0))
object.BackgroundColor3 = Color3.fromRGB(102, 255, 0)
wait(1)
object:TweenPosition(UDim2.new(.6,0,.6,0))
object.BackgroundColor3 = Color3.fromRGB(145, 255, 0)
wait(.9)
object:TweenPosition(UDim2.new(.3,.5,.3,.5))
object.BackgroundColor3 = Color3.fromRGB(188, 255, 1)
wait(.9)
object.Text = "Hurry!"
object:TweenPosition(UDim2.new(.3,.5,.7,.2))
object.BackgroundColor3 = Color3.fromRGB(200, 255, 2)
wait(.8)
object:TweenPosition(UDim2.new(.3,.3,.3,.3))
object.BackgroundColor3 = Color3.fromRGB(243, 255, 3)
wait(.8)
object:TweenPosition(UDim2.new(.9,.0,.1,.35))
object.BackgroundColor3 = Color3.fromRGB(255, 234, 2)
object.TextColor3 = Color3.fromRGB(255, 0, 0)
wait(.7)
object:TweenPosition(UDim2.new(0,0,0,0))
object.BackgroundColor3 = Color3.fromRGB(255, 162, 0)
wait(.7)
object:TweenPosition(UDim2.new(.3,0,.5,0))
object.BackgroundColor3 = Color3.fromRGB(255, 102, 0)

wait(.65)
object:TweenPosition(UDim2.new(0,0,0,0))
object.BackgroundColor3 = Color3.fromRGB(255, 59, 0)
wait(.65)
object:TweenPosition(UDim2.new(.5,0,0,0))
object.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
wait(.6)
script.Parent.Text = "Game over!"
wait(1.5)
object.Parent:Destroy()

Character.Head.CFrame = game.Workspace.ColorIsland.VIPBuilding.VipDoor.VipDoorBackTp.CFrame + Vector3.new(0,3,0)

function touch ()

script.Parent.Text = "You Won!"
wait(2)
Character.Head.CFrame = game.Workspace.ColorIsland.VIPBuilding.VipDoor.VipDoorBackTp.CFrame + Vector3.new(0,3,0)
script.Parent.Parent:Destroy()
end

object.MouseButton1Click:Connect(touch)

Everything works fine until I try to click on it, nothing happens. It is supposed to display the text “You won!”

1 Like

That could be due to the amount of wait()'s you had included in your script - therefore, yielding the event for clicking (hence delayed). Use a coroutine.wrap() for your tweening parts to avoid this.

coroutine.wrap(function()
wait(1) --start of your tweening code
--the rest
object.Parent:Destroy() --end of your tweening code
end)()
--rest of the code here
1 Like

Like this?

coroutine.wrap(function()
local object = script.Parent
local Character = game.Players.LocalPlayer.Character
local CanWin = true
object.AnchorPoint = Vector2.new(.5,.5)
object.Position = UDim2.new(.1,0,.5,0)

wait(1)
object:TweenPosition(UDim2.new(.5,0,.5,0))
object.BackgroundColor3 = Color3.fromRGB(102, 255, 0)
wait(1)
object:TweenPosition(UDim2.new(.6,0,.6,0))
object.BackgroundColor3 = Color3.fromRGB(145, 255, 0)
wait(.9)
object:TweenPosition(UDim2.new(.3,.5,.3,.5))
object.BackgroundColor3 = Color3.fromRGB(188, 255, 1)
wait(.9)
object.Text = "Hurry!"
object:TweenPosition(UDim2.new(.3,.5,.7,.2))
object.BackgroundColor3 = Color3.fromRGB(200, 255, 2)
wait(.8)
object:TweenPosition(UDim2.new(.3,.3,.3,.3))
object.BackgroundColor3 = Color3.fromRGB(243, 255, 3)
wait(.8)
object:TweenPosition(UDim2.new(.9,.0,.1,.35))
object.BackgroundColor3 = Color3.fromRGB(255, 234, 2)
object.TextColor3 = Color3.fromRGB(255, 0, 0)
wait(.7)
object:TweenPosition(UDim2.new(0,0,0,0))
object.BackgroundColor3 = Color3.fromRGB(255, 162, 0)
wait(.7)
object:TweenPosition(UDim2.new(.3,0,.5,0))
object.BackgroundColor3 = Color3.fromRGB(255, 102, 0)

wait(.65)
object:TweenPosition(UDim2.new(0,0,0,0))
object.BackgroundColor3 = Color3.fromRGB(255, 59, 0)
wait(.65)
object:TweenPosition(UDim2.new(.5,0,0,0))
object.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
wait(.6)
script.Parent.Text = "Game over!"
wait(1.5)
object.Parent:Destroy()

Character.Head.CFrame = game.Workspace.ColorIsland.VIPBuilding.VipDoor.VipDoorBackTp.CFrame + Vector3.new(0,3,0)
end)
function touch ()
local Character = game.Players.LocalPlayer.Character
script.Parent.Text = "You Won!"
wait(2)
Character.Head.CFrame = game.Workspace.ColorIsland.VIPBuilding.VipDoor.VipDoorBackTp.CFrame + Vector3.new(0,3,0)
script.Parent.Parent:Destroy()
end

object.MouseButton1Click:Connect(touch)

Pretty much, I guess. Also make sure to put a () and the end of the coroutine so that part of code runs.

1 Like