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

Why does my script only work in solo testing?

I made this script and it works perfect in solo testing but it doesn't work in normal game.

while true do
    game.Players.LocalPlayer.leaderstats.Score.Value = game.Players.LocalPlayer.leaderstats.Score.Value + 1
	local str = game.Players.LocalPlayer.leaderstats.Score.Value
	local str1 = "Your income: "
	game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.TextButton.Text = str1..str
	wait(1)	
end

1 answer

The most common cause for a LocalScript to malfunction in a sever environment is an attempt to access something that is instantiated very quickly when run locally, but more slowly on a server, for example ... the Player!

All you need to do is add a loop that waits until the player, and in some cases the specific thing that you want, exist:

while not game.Players.LocalPlayer do wait() end
player = game.Players.LocalPlayer

while not player:FindFirstChild("leaderstats") do wait() end
stats = player.leaderstats

while true do
    stats.Score.Value = stats.Score.Value + 1
    local str = stats.Score.Value
    local str1 = "Your income: "
    player.PlayerGui.ScreenGui.Frame.TextButton.Text = str1..str
    wait(1) 
end

2 comments

0

This doesn't seem to be working.

0

What is not working about it? Have you looked at the Output? What does it say? You even have something called "leaderstats" under the Player?

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