My goal is after the (moveCheese) function plays and wait(2) the text appears.
code:
local cheese = script.Parent
local Button = game.Workspace.Button.ClickDetector
local dir = 1
local MTEXT = game.StarterGui.ScreenGui.TextLabel
local function meanText()
game.StarterGui.ScreenGui.TextLabel.Visible = true
end
local function moveCheese()
while true do
cheese.Position = cheese.Position + Vector3.new(0,1*dir,0)
wait(.15)
if (cheese.Position.Y > 10) then
dir = -1
end
if (cheese.Position.Y < 5) then
dir = 1
end
end
end
Button.MouseClick:Connect(moveCheese)
wait(2)
Button.MouseClick:Connect(meanText)
The main problem is on line 28 but I’m not getting any errors, pretty sure it’s to do with the text but I can’t fix it.
Try changing your code to the one below. I believe it’s because on the moveCheese() function you’re running the while true do loop and not spawning/wrapping it - So it’ll never advance from that loop. I also have included the task library into your code, Let me know if it works.
local cheese = script.Parent
local Button = workspace:WaitForChild("Button"):WaitForChild("ClickDetector")
local MTEXT = game:GetService("StarterGui"):WaitForChild("ScreenGui"):WaitForChild("TextLabel")
local dir = 1
local function meanText()
MTEXT.Visible = true
end
local function moveCheese()
task.spawn(function()
while true do
cheese.Position = cheese.Position + Vector3.new(0, 1 * dir,0)
task.wait(.15)
if (cheese.Position.Y > 10) then
dir = -1
elseif (cheese.Position.Y < 5) then
dir = 1
end
end
end)
end
Button.MouseClick:Connect(moveCheese)
task.wait(2)
Button.MouseClick:Connect(meanText)
Hmm, I think you could try this then, Not sure. If what you’re trying to do is to make the Text show after 2 seconds, Then you can replace the last 3 lines of code with this:
You are trying to change it in Starter Gui, which is replicated to the player instance when they spawn. You should be changing it locally, so here is the code:
local cheese = script.Parent
local Button = game.Workspace.Button.ClickDetector
local dir = 1
local MTEXT = game.Players.LocalPlayer.PlayerGui.TextLabel
local function meanText()
MTEXT.Visible = true
end
local function moveCheese()
while true do
cheese.Position = cheese.Position + Vector3.new(0,1*dir,0)
wait(.15)
if (cheese.Position.Y > 10) then
dir = -1
end
if (cheese.Position.Y < 5) then
dir = 1
end
end
end
Button.MouseClick:Connect(moveCheese)
wait(2)
Button.MouseClick:Connect(meanText)
As yes, a throwback to my exploiting days on the ROBLOX platform where I learned the insides and outs of many different games. I believe what you are looking for is
spawn(moveCheese)
spawn(meanText)
the way we would use these is as following;
textButtonClicked
spawn(
function()
moveCheese()
end
)
textButtonClicked
spawn(
function()
meanText()
end
)
Don’t know if this will help you any but it allows us to run multiple if not infinite while true loops all at once, you can achieve the same with a coroutine if you would prefer it, you call a coroutine with a while true loop or generally whatever you want in it and it wont break your script.
local cheese = script.Parent
local Button = game.Workspace.Button.ClickDetector
local dir = 1
local MTEXT = game.StarterGui.ScreenGui.TextLabel
local function meanText()
spawn(
function()
game.StarterGui.ScreenGui.TextLabel.Visible = true
end
)
end
local function moveCheese()
spawn(
function()
while true do
cheese.Position = cheese.Position + Vector3.new(0,1*dir,0)
wait(.15)
if (cheese.Position.Y > 10) then
dir = -1
end
if (cheese.Position.Y < 5) then
dir = 1
end
end
end
)
end
Button.MouseClick:Connect(moveCheese)
Button.MouseClick:Connect(meanText)