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)
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
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)