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

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

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?

4 comments

0

I know this is long, but pls help me with this!

0

You're probably trying to reference objects that aren't there yet. Try using WaitForChild.

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

1 answer

✓ Accepted answer

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.

1 comment

0

Thanks! My solution is to use WaitForChild() and some variables! :D

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