Hello! My point system (gives you points when you walk) stops working when you die. Does anyone know how to fix this?
--SAVE SYSTEM--
local DSService = game:GetService('DataStoreService'):GetDataStore('Hamburger223232')
game.Players.PlayerAdded:connect(function(plr)
-- Define variables
local uniquekey = 'id-'..plr.userId
local leaderstats = Instance.new('IntValue', plr)
local savevalue = Instance.new('IntValue')
leaderstats.Name = 'leaderstats'
savevalue.Parent = leaderstats
savevalue.Name = 'Steps'
-- GetAsync
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue.Value = GetSaved[1]
else
local NumbersForSaving = {savevalue.Value}
DSService:SetAsync(uniquekey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Steps.Value}
DSService:SetAsync(uniquekey, Savetable)
end)
--POINT ADDER--
local amount = 1;
local points = "Steps";
local wte = wait;
local vec3 = Vector3;
local function CheckForWalk(plr, hum)
pcall(function()
while wte() do
if hum.MoveDirection ~= vec3.new(0, 0, 0) then --if the character is moving
while wte(1/plr.leaderstats["Steps"].Value) do --while the player is moving, increase their step points each second.
if hum.MoveDirection ~= vec3.new(0, 0, 0) then
plr.leaderstats[points].Value = plr.leaderstats[points].Value + amount;
else
break;
end
end
end
end
end);
end
game.Players.PlayerAdded:connect(function(plr)
repeat
wte();
until plr.Character;
local hum = plr.Character:WaitForChild("Humanoid");
CheckForWalk(plr, hum);
plr.Changed:connect(function(prop)
repeat wte() until plr.Character;
local hum = plr.Character:WaitForChild("Humanoid");
CheckForWalk(plr, hum);
end);
end);

8 comments
It seems to have the same problem :(
Actually, it fixed one of the problems. The only issue is if you hold in "W" it breaks and gives you points when you aren't walking. Sorry if I'm asking too much, but do you know why that happens?
You could implement a http://wiki.roblox.com/index.php?title=Debounce
I would just need to make it so when the player dies, it stops the function from running for 10 seconds.
Do you know how I could do that?
Already told you :)
I understand what you mean now. Sorry, I didn't really know how check if a player died. I think I got it, and I can add wait(5) under it as a debounce. Thanks for helping me out.
No problem :D I was hoping you'd either figure it out or ask another question about debounce. Happy developing.