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

Show a player a GUI when their level changes, script not working. Why?

The script it supposed to show the player a GUI when their level changes. I'm not sure why this script doesn't work because I used a very similar script to reset the players points when their level changes and it works. I'm a new developer so I'm sure that there's something that I'm missing. Also, can someone tell me why the non-working script doesn't work and why the other script does work? (Yes, the game is FE.)

Non-working script:

game.Players.PlayerAdded:Connect(function(plr)
	
    local LSystem = plr:WaitForChild("LevelSystem")
    local PStats = plr:WaitForChild("PlayerStats")
    local level = LSystem:WaitForChild("Level")
    local points = PStats:WaitForChild("Points")

    level.Changed:Connect(function(val)
        script.Parent.Visible = true
    end)
end)

Similar script that works:

game.Players.PlayerAdded:Connect(function(plr)
	
    local LSystem = plr:WaitForChild("LevelSystem")
    local PStats = plr:WaitForChild("PlayerStats")
    local level = LSystem:WaitForChild("Level")
    local points = PStats:WaitForChild("Points")

    level.Changed:Connect(function(val)
        points.Value = 0
    end)
end)

1 answer

I think your non-working script needs to be a localscript.

In the second script, it looks fine and the value changes most likely because a server (regular) script is doing it. But in the first script, you’re trying to making a GUI visible, and I’m assuming you’re using a server script for that too. Don’t use server scripts in GUI, unless you’re using a SurfaceGui.

Just replace your non-working script with a localscript. :P

4 comments

0

It was in a local script D:

0

Oh. Are you getting any “Infinite Yield Possible” warnings in your console? If not, it’s probably line 8 that’s the problem.

0

Yes, ideas on how I can make it work?

0

If you’re getting those warnings, that means from lines 3-6, the script can’t find one or more of whatever you’re trying to find. Make sure the objects the script is trying to find are there, there aren’t any typos on them, and they’re looking at the correct place.

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