Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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

0
No, it's a regular script. ChurroRX 15 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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.

0
Oh, I understand it now. Alright, thanks. ChurroRX 15 — 6y

Answer this question