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

Anybody know what's wrong with this function script, I can't find the error?

I'm trying to make a script that makes a gui appear only if a player has surpassed a certain leaderstat, this is the code I have so far and there's nothing wrong with the Parents or anything like that so I can't find my error, any help?

player = script.Parent.Parent.Parent.Parent
stats = player:WaitForChild("leaderstats")
Level = stats:WaitForChild("Level")

game.Players.PlayerAdded:connect(function()
if Level.Value >= 50 then
script.Parent.Visible = true
end
end)

4 comments

0

BTW the parent is a frame so the visible = true should work

0

The script in which this code resides probably loads after the player has been added to the game, so the PlayerAdded event won't fire. I'd suggest putting this in a LocalScript and doing the level check directly rather than waiting for an event.

0

How would I do it directly, can you give an example using my code?

0

I think I see it, look at what I write and see if it works

2 answers

1:  player = script.Parent.Parent.Parent.Parent
2: stats = player:WaitForChild("leaderstats")
3: Level = stats:WaitForChild("Level")
4: game.Players.PlayerAdded:connect(function()
5: if Level.Value = 50 then
6: script.Parent.Visible = true
7: end
8: end)

You messed up and wrote a > which messes up the script

3 comments

0

Try using this script

0

No, that was on purpose, it means greater than or equal to, thanks for trying though :)

0

You also are supposed to do: == when it comes to if then statements.

You're trying to index player and are also using PlayerAdded. That tells me you're trying to use this in a LocalScript in PlayerGui. You can't use PlayerAdded in this way. You can use ChildAdded, but either way, what you seem to be doing isn't going to work.

This needs to be in a LocalScript

local players = game:GetService("Players")
local player = players.LocalPlayer
local stats = player:WaitForChild("leaderstats")
local Level = stats:findFirstChild("Level")

if not Level then print("Can't find level") return end
if Level.Value >= 50 then  -- First check to see each time we respawn with the GUI
	script.Parent.Visible = true
end

Level.Changed:connect(function() -- Every check after level changes
	if Level.Value >= 50 and not script.Parent.Visible then 
		script.Parent.Visible = true
	end
end)

1 comment

0

Thanks so much for all of this and I know this is going to sound annoying but this still doesn't work and I can't find an error with what you gave me like it makes no sense as to why it doesn't work

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