I am using the script below to check if a player’s “Prizes Won” leaderstat is above or equal to 100. If so, a RemoteEvent should be fired.
local event = game.ReplicatedStorage:WaitForChild("RemoveClawDoor")
local door = game.Workspace:WaitForChild("HundredDoor")
game.Players.PlayerAdded:Connect(function(plr)
if plr.leaderstats["Prizes Won"].Value >= 100 then
event:FireClient(plr,door)
end
plr.leaderstats["Prizes Won"].Value:GetPropertyChangedSignal("Value"):Connect(function()
if plr.leaderstats["Prizes Won"].Value >= 100 then
event:FireClient(plr,door)
end
end)
end)
I’m not quite sure if I’ve gotten the leaderstat value correctly as it seems that the script never gets inside the if statements. Is this the issue, and if so, how do I fix it?
this wont work because you are already referencing value
this wont work because it probably doesnt exist yet
anyway i hope this works for you
local event = game.ReplicatedStorage:WaitForChild("RemoveClawDoor")
local door = game.Workspace:WaitForChild("HundredDoor")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = plr:WaitForChild("leaderstats")
local prizes: IntValue = leaderstats:WaitForChild("Prizes Won")
if prizes.Value >= 100 then
event:FireClient(plr, door)
end
prizes:GetPropertyChangedSignal("Value"):Connect(function()
if prizes.Value >= 100 then
event:FireClient(plr, door)
end
end)
end)
Atop @Inkthirsty’s notes, there is no need for you to involve the server here. The leaderstat in question is available for observation by the client, and replicates naturally. The local player can easily set up its own script to react to changes in that leaderstat. This is ultimately more responsive. On another note, you do not need to use Instance:GetPropertyChangedSignal to read changes in the “Value” property. All ValueBase descendants expose a modified Instance.Changed event that provides its callbacks with the new state of the “Value” property