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

This script will work in studio when I test it. But when I play in-game it doesnt. Help?

local TL = script.Parent.Parent.TL
local TI = script.Parent.Parent.TI
local TF = game.Players.LocalPlayer.stats.TotalFollowers
local ClickValue = script.CV

TL.MouseButton1Up:connect(function()
	TF.Value = TF.Value + ClickValue.Value
	x = math.random(400)
	TI.Visible = true
	TI.Position = UDim2.new(0,x,0,0)
	TI:TweenPosition(UDim2.new(0,x,1,0, "Out", "Quad", 5))
	print("Clicked!")
end)

This is a LocalScript inside a ImageButton

1 comment

0

any errors in Output? if not, trying adding more Prints

1 answer

Hey, I also had this problem happening to me so many times and this problem is a common problem for scripters who use LocalScript!

According to this site, It stats that LocalScript are the script which will begin downloading the Client's world and begin to run before any other objects have been downloaded!

My advice is that at the beginning of every LocalScript you should add wait() command. If you do not understand what I mean then let me show you an example using your script:

wait(0.1) -- you can set it to how much time it should wait, I normally type in 0.1.

local TL = script.Parent.Parent.TL
local TI = script.Parent.Parent.TI
local TF = game.Players.LocalPlayer.stats.TotalFollowers
local ClickValue = script.CV

TL.MouseButton1Up:connect(function()
    TF.Value = TF.Value + ClickValue.Value
    x = math.random(400)
    TI.Visible = true
    TI.Position = UDim2.new(0,x,0,0)
    TI:TweenPosition(UDim2.new(0,x,1,0, "Out", "Quad", 5))
    print("Clicked!")
end)

Other than that everyone looks fine for me.

I hope this answer helps you. If you need any more question, feel free to ask me and I will be happy to help you in any way. :)

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