The script below does not work for me, I have given myself the correct amount of points in order to unlock the door, but it does not do anything.
local player = game.Players.LocalPlayer
local points = player.leaderstats:WaitForChild("Points") --The points leaderstat
local part = workspace:WaitForChild("Unlock Door") --The unlockable door
if points.Value >= 20 then
part.CanCollide = false
part.Transparency = 0.5
part.Anchored = true
else
part.CanCollide = true
part.Transparency = 0
part.Anchored = false
end
No errors, tried doing stuff like putting the script in the part, that doesn’t work.
Thanks!
You should use either the Changed event or GetPropertyChangedSignal event to detect any change of the value, because as what @CZXPEK said above, the code you have given will only run once.
Here is your updated script (I have optimized your code a little bit):
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local points = leaderstats:WaitForChild("Points") --The points leaderstat
local part = workspace:WaitForChild("Unlock Door") --The unlockable door
if points.Value >= 20 then -- this statement will run as soon as the player joins
part.CanCollide = false
part.Transparency = 0.5
part.Anchored = true
else
part.CanCollide = true
part.Transparency = 0
part.Anchored = false
end
points:GetPropertyChangedSignal("Value"):Connect(function() -- detects any changes to the 'Points' Value
if points.Value >= 20 then
part.CanCollide = false
part.Transparency = 0.5
part.Anchored = true
else
part.CanCollide = true
part.Transparency = 0
part.Anchored = false
end
end)