Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

GUI-Text changing script works in studio but breaks in-game. Why?

I have a problem with a script. The script works completely fine in studio, but does not work in game at all and the developer console shows no error messages. I've seen this problem happen frequently to others and I can't figure out how to fix it. I'm a beginner scripter, so I'm unaware of a solution to this. It is a regular script, not a LocalScript.

Finished = true
function onClicked(click)
if (script.Parent.Parent.Value1.Value == 0) and Finished == true then
Finished = false
game.Players.LocalPlayer.PlayerGui.TotalNumber.TextLabel.Text = "1"
wait(3)
game.Players.LocalPlayer.PlayerGui.TotalNumber.TextLabel.Text = ""
Finished = true
elseif (script.Parent.Parent.Value1.Value == 1) and Finished == true then
Finished = false
game.Players.LocalPlayer.PlayerGui.TotalNumber.TextLabel.Text = "2"
wait(3)
game.Players.LocalPlayer.PlayerGui.TotalNumber.TextLabel.Text = ""
Finished = true
elseif (script.Parent.Parent.Value1.Value == 2) and Finished == true then
Finished = false
game.Players.LocalPlayer.PlayerGui.TotalNumber.TextLabel.Text = "3"
wait(3)
game.Players.LocalPlayer.PlayerGui.TotalNumber.TextLabel.Text = ""
Finished = true
elseif (script.Parent.Parent.Value1.Value == 3) and Finished == true then
Finished = false
game.Players.LocalPlayer.PlayerGui.TotalNumber.TextLabel.Text = "4"
wait(3)
game.Players.LocalPlayer.PlayerGui.TotalNumber.TextLabel.Text = ""
Finished = true
elseif (script.Parent.Parent.Value1.Value == 4) and Finished == true then
Finished = false
game.Players.LocalPlayer.PlayerGui.TotalNumber.TextLabel.Text = "5"
wait(3)
game.Players.LocalPlayer.PlayerGui.TotalNumber.TextLabel.Text = ""
Finished = true
elseif (script.Parent.Parent.Value1.Value == 5) and Finished == true then
Finished = false
game.Players.LocalPlayer.PlayerGui.TotalNumber.TextLabel.Text = "6"
wait(3)
game.Players.LocalPlayer.PlayerGui.TotalNumber.TextLabel.Text = ""
Finished = true
elseif (script.Parent.Parent.Value1.Value == 6) and Finished == true then
Finished = false
game.Players.LocalPlayer.PlayerGui.TotalNumber.TextLabel.Text = "7"
wait(3)
game.Players.LocalPlayer.PlayerGui.TotalNumber.TextLabel.Text = ""
Finished = true
elseif (script.Parent.Parent.Value1.Value == 7) and Finished == true then
Finished = false
game.Players.LocalPlayer.PlayerGui.TotalNumber.TextLabel.Text = "8"
wait(3)
game.Players.LocalPlayer.PlayerGui.TotalNumber.TextLabel.Text = ""
Finished = true
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

2 answers

✓ Accepted answer

I am assuming that this is in a local script as you use game.Players.LocalPlayer.

A LocalScript will only run Lua code if it is a descendant of one of the following objects: -A Player's Backpack, such as a child of a Tool -A Player's Character model -A Player's PlayerGui -A Player's PlayerScripts -The ReplicatedFirst service

1 comment

0

No, it's a regular script.

As what JackOfAllBlox stated, You should only use game.Players.LocalPlayer when you are running a LocalScript. So change it to a LocalScript and it should work.

1 comment

0

Oh, I understand it now. Alright, thanks.

This discussion is preserved as it was. New answers, comments, and votes are closed.