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

Dealing with "Works in Studio, but not online" effect?

Asked by 8 years ago

I was working on a Gui which contains a player's statistics for a sword fighting game. However, it only works in play solo, but not on a test server. I think it is because of a "Works in Studio, but not online effect" :(

Here are the errors in the test server: 12:02:54.479 - Credits is not a valid member of TextLabel 12:02:54.479 - Script 'Players.Player1.PlayerGui.StatGui.StatFrame.Credits.TextLabel.LocalScript', Line 1 12:02:54.480 - Stack End 12:02:54.480 - Wins is not a valid member of TextLabel 12:02:54.480 - Script 'Players.Player1.PlayerGui.StatGui.StatFrame.Wins.TextLabel.LocalScript', Line 3 12:02:54.481 - Stack End 12:02:54.481 - Level is not a valid member of TextLabel 12:02:54.481 - Script 'Players.Player1.PlayerGui.StatGui.StatFrame.EXP.Level.LocalScript', Line 1 12:02:54.482 - Stack End 12:02:54.482 - EXP is not a valid member of TextLabel 12:02:54.482 - Script 'Players.Player1.PlayerGui.StatGui.StatFrame.EXP.EXP.LocalScript', Line 2 12:02:54.483 - Stack End

Here are the scripts: (P.S. All of them are local scripts!)

Credits

script.Parent.Text = script.Parent.Credits.Value
script.Parent.Credits.Changed:connect(function()
    script.Parent.Text = script.Parent.Credits.Value
end)

Wins

script.Parent.Text = script.Parent.Wins.Value
script.Parent.Wins.Changed:connect(function()
    script.Parent.Text = script.Parent.Wins.Value
end)

EXP

local Player = game.Players.LocalPlayer
local EXP = script.Parent.EXP 
local level = script.Parent.Parent.Level.Level
local target = script.Parent.Target


script.Parent.Text = EXP.Value..' / '..target.Value
EXP.Changed:connect(function()
    script.Parent.Text = EXP.Value
    if EXP.Value >= target.Value then
        level.Value = level.Value + 1
        EXP.Value = EXP.Value - target.Value
        target.Value = 100*level.Value + 10*(level.Value-1)
        repeat until EXP.Value < target.Value
    end
    script.Parent.Text = EXP.Value..' / '..target.Value
end)

Level

local level = script.Parent.Level

script.Parent.Text = 'Lv. '..level.Value
level.Changed:connect(function()
    script.Parent.Text = 'Lv. '..level.Value
end)

How should I change the scripts to make them Work in BOTH Studio and Online?

0
I know this is long, but pls help me with this! starlebVerse 685 — 8y
0
You're probably trying to reference objects that aren't there yet. Try using WaitForChild. LightningRoMan 100 — 8y
0
Well! Thanks, LightningRoMan! The problem is solved! Next time, try answering it by making an example on one of the scripts instead of commenting, so I can accept your answer and we can get reputation points! :D starlebVerse 685 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

Your hierarchy is wrong

script.Parent is already the TextLabel you're looking for in all of the scripts, causing the issue you're experiencing.

Alternatively, if you have some dodgy naming going on, your issue is that you're not using WaitForChild to ensure that the Instances you need are replicated by the time your code runs.

0
Thanks! My solution is to use WaitForChild() and some variables! :D starlebVerse 685 — 8y
Ad

Answer this question