-- remotefunctions kk --serverscript DS = game:GetService("DataStoreService"):GetDataStore("votes") event = game.ReplicatedStorage.Events.VotePlayer1 event.OnServerEvent:connect(function() DS:UpdateAsync("player1", function(oldValue) return oldValue + 1 end) end) -- inside the gui button -- parenting rs = game.ReplicatedStorage events = rs.Events votefunction = events:FindFirstChild("VotePlayer1") -- script local button = script.Parent button.MouseButton1Down:connect(function() votefunction:FireServer() end)
This gives this error:
ServerScriptService.Script:13: attempt to perform arithmetic on local 'oldValue' (a nil value)
How would I define a value, this are all scripts I have..
but I have no clue how to fix this
The solution is in the error message. Apparently "oldValue" has returned nil for some reason, or wasn't returned at all. We can fix this by simply adding an "and" and "or" statement like so:
DS = game:GetService("DataStoreService"):GetDataStore("votes") event = game.ReplicatedStorage.Events.VotePlayer1 event.OnServerEvent:connect(function() DS:UpdateAsync("player1", function(oldValue) return oldValue and oldValue+1 or 1 -- if old, then add 1. if not, return 1 end) end) rs = game.ReplicatedStorage events = rs.Events votefunction = events:FindFirstChild("VotePlayer1") local button = script.Parent button.MouseButton1Down:connect(function() votefunction:FireServer() end)