Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

When Player Touches Brick, Gain + 1 Win in Leaderboard, Why It's not working?

Asked by 5 years ago

It Doesn't Work

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("winsSaveSystem")--change all "wins" to what value you want and keep doing it 
local Debounce = tick() -- Assign tick() to the variable
game.Players.PlayerAdded:connect(function(player)
 local folder = Instance.new("Folder", player)
 folder.Name = "leaderstats"
 local wins = Instance.new("IntValue", folder)
 wins.Name = "Wins"
 wins.Value = ds1:GetAsync(player.UserId) or 0
 ds1:SetAsync(player.UserId, wins.Value)

workspace.Lobby.DROPDOWN.Winner.Touched:Connected(function()
    if (tick() - Debounce) >= 5 then -- Make sure 5 seconds have elapsed since last debounce
        Debounce = tick()
            wins.Value = wins.Value + 1


    end
end)



 wins.Changed:connect(function()
  ds1:SetAsync(player.UserId, wins.Value)
 end)



end)

0
Might want to capitalize Connect, because the lowercased version is deprecated. meteorcrasher118 35 — 5y
0
It doesn't work because you wrote Connected on line 12. SummerEquinox 643 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("winsSaveSystem")
local Debounce = tick()
game.Players.PlayerAdded:Connect(function(player)
 local folder = Instance.new("Folder")
 folder.Parent = player --second argument of .new() deprecated
 folder.Name = "leaderstats"
 local wins = Instance.new("IntValue")
 wins.Parent = folder
 wins.Name = "Wins"
 wins.Value = ds1:GetAsync(player.UserId) or 0
 ds1:SetAsync(player.UserId, wins.Value)

workspace.Lobby.DROPDOWN.Winner.Touched:Connect(function() --not Connected
    if (tick() - Debounce) >= 5 then
        Debounce = tick()
            wins.Value = wins.Value + 1


    end
end)



 wins.Changed:Connect(function() --uppercase C
  ds1:SetAsync(player.UserId, wins.Value)
 end)



end)
0
you shouldnt save your datastore everytime wins changes. you're going to overload the datastore Gey4Jesus69 2705 — 5y
0
Furthermore, you shouldn't set the parent first, it should be the last thing you do in most cases. turtle2004 167 — 5y
Ad

Answer this question