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

Why does my script only work in solo testing?

Asked by
NecoBoss 194
10 years ago

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

Log in to vote
0
Answered by
duckwit 1404 Moderation Voter
10 years ago

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
0
This doesn't seem to be working. NecoBoss 194 — 10y
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? duckwit 1404 — 10y
Ad

Answer this question