I am trying to achive a leaderboard system that you can use points to get past doors
** The Problem**
Basically how the points work is it uses a point per second system, but whenever you try to subtract the points from the door it just adds all the points back up again.
game.Players.PlayerAdded:connect(function(p)
local stats = Instance.new("IntValue", p)
stats.Name = "leaderstats"
local wins = Instance.new("IntValue", stats)
wins.Name = "Wins"
local Points = Instance.new("IntValue", stats)
Points.Name = "Points"
local x = wins.Value
Points.Value = 0
while true do
wait(1)
Points.Value = Points.Value + 1 + wins.Value
end
end)
** Lmk if you see any parts of my script that would be causing this problem, and I will be countinusly trying to solve this aswell.**
This works, but whenever I enter the point door it subtracts it to go back to 0 and then just jumps right back up to whatever it was at.
Heres my local script if this is the problem
local Workspace = game:GetService("Workspace")
local door = Workspace.Door
door.Touched:Connect(function(hit)
local human = hit.Parent:FindFirstChild("Humanoid")
if human ~= nil then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr.leaderstats.Points.Value >= door.Value.Value then
script.Enabled = false
plr.leaderstats.Points.Value = plr.leaderstats.Points.Value - door.Value.Value
door.Transparency = 0.5
door.CanCollide = false
wait(1)
door.Transparency = 0
door.CanCollide = true
wait(5)
script.Enabled = true
end
end
end)
It a local script meaning it will not work
Common error but if you ever edit a server value via the local script then the server will still see it as it was before the local script did anything
Iâm a little lost in this thread, but heading back to the original problem, you said the value keeps jumping back up correct? I presume the problem is related to this line of code being ran in a local script.
You need to change datastore values via the server and not the client. This is because it is local (in the name), while changing on the server will be a global change. I suggest finding some way to notify the server for when a user touches the door and change the value through a server script.