Instance.Changed() not working for me

So I’m trying to make my own admin cmds from scratch, and I want to detect if the value changed, but it’s not doing anything at all. here is the script:

local powertable = {
	[1] = "Visitor",
	[5] = "VIP",
	[10] = "Trial Moderator",
	[25] = "Moderator",
	[50] = "High Moderator",
	[100] = "Administrator",
	[200] = "Co-Owner",
	[255] = "Owner",
}

game.Players.PlayerAdded:Connect(function(player)
	if player.UserId ~= game.CreatorId then
		local Rank = Instance.new("NumberValue")
		Rank.Value = 1
		Rank.Parent = player
		Rank.Changed:Connect(function()
			print(Rank.Value)
			if Rank.Value >= 5 then
				local PlayerGUI = player.PlayerGui
				local Frame = PlayerGUI.yes.Frame
				Frame.Visible = true
				for i, v in pairs(powertable) do
					if i == Rank.Value then
						Frame.TextLabel.Text = "Your ingame rank is "..v
					end
				end
			end
		end)
	else
		local Rank = Instance.new("NumberValue")
		Rank.Value = 255
		Rank.Parent = player
	end
end)

How can I fix the issue?

2 Likes
if player.UserId ~= game.CreatorId then

the script won’t run unless you’re not the creator.

1 Like

also, you can use

Rank:GetPropertyChangedSignal("Value"):Connect(function()

instead of

Rank.Changed:Connect(function()

where are you setting the rank value or changing it at? another script?

You’re only creating the Rank.Changed connection when the player isn’t you (the creator). You just need to move that bit outside of the if statement and only set the value instead

game.Players.PlayerAdded:Connect(function(player)
	local Rank = Instance.new("NumberValue")
	if player.UserId ~= game.CreatorId then
		Rank.Value = 1
	else
		Rank.Value = 255
	end

	Rank.Parent = player

	Rank.Changed:Connect(function()
		print(Rank.Value)
		if Rank.Value >= 5 then
			local PlayerGUI = player.PlayerGui
			local Frame = PlayerGUI.yes.Frame
			Frame.Visible = true
			for i, v in pairs(powertable) do
				if i == Rank.Value then
					Frame.TextLabel.Text = "Your ingame rank is "..v
				end
			end
		end
	end)
end)

That is only for the first bit of the if block

You can, but that doesn’t really mean you should. The Changed event is different for ObjectValues and behaves the same as using GetPropertyChangedSignal("Value") would

3 Likes

yeah, im not the owner tho, everytime i join im rank 1.

nah, im changing through the explorer

is that a localscript or a serverscript?

server script, it would be weird for admin perms to run on localscript.

its not printing

print(Rank.Value)

right?

nope, it’s printing out other stuff that have nothing to do with this particular script

try this

local powertable = {
	[1] = "Visitor",
	[5] = "VIP",
	[10] = "Trial Moderator",
	[25] = "Moderator",
	[50] = "High Moderator",
	[100] = "Administrator",
	[200] = "Co-Owner",
	[255] = "Owner",
}

game.Players.PlayerAdded:Connect(function(player)
local Rank = Instance.new("NumberValue")
	if player.UserId ~= game.CreatorId then
		Rank.Value = 1
		Rank.Parent = player
else
		Rank.Value = 255
		Rank.Parent = player
	end
end
		Rank.Changed:Connect(function()
			print(Rank.Value)
			if Rank.Value >= 5 then
				local PlayerGUI = player.PlayerGui
				local Frame = PlayerGUI.yes.Frame
				Frame.Visible = true
				for i, v in pairs(powertable) do
					if i == Rank.Value then
						Frame.TextLabel.Text = "Your ingame rank is "..v
				end
                         end
			end
		end)
	
end)

did not work, nothing is popping up, nothing is printing.

Are you changing in the Explorer from the perspective of the client, not the server, because NumberValues can’t be changed from the Client?

1 Like

yes, thats what im doing, ill try changing it from the server perspective

1 Like

this works from server’s perspective, thank you!