I just recoded my leaderstats to take savedata but now I'm experiencing a problem with my points giver, it worked fine before and I havent touched my points giving script for months so I kinda dont remember what I did to get it to work last time. Anyway, Heres the coding. I'm not sure if I just messed up in thew leaderstats coding or not because it no longer says points for the name, it says Value. ohh so confusing.
I get this error in the output
Workspace.Map1.TeleporterA.+Points:16: attempt to index local 'Points' (a nil value)
-------------------------
onPlayerAdded:
-------------------------
local DataStore = game:GetService("DataStoreService"):GetDataStore("FEDSC")
game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"
local points = Instance.new("IntValue", stats)
points.name = "Points"
local coins = Instance.new("IntValue", stats)
coins.Name = "Coins"
local key = "player-"..player.userId
local savedValues = DataStore:GetAsync(key)
if savedValues then
--Save fortmat: {points, coins}
points.Value = savedValues[1]
coins.Value = savedValues[2]
else
local valuesToSave = {points.Value, coins.Value}
DataStore:SetAsync (key, valuesToSave)
end
end)
-------------------------
playerLeaving (saving):
-------------------------
local DataStore = game:GetService("DataStoreService"):GetDataStore("FEDSC")
game.Players.PlayterRemoving:connect(function(player)
local key = "player-"..userId
--Save key: {points, coins}
local valuesToSave = {player.leaderstats.Points.Value, player.leaderstats.Coins.Value}
DataStore:SetAsync
end)
-------------------------
+Points
-------------------------
local ting = 0 --debouncer
function onTouched(hit)
if ting == 0 then --debounce check
ting = 1 --activate debounce
check = hit.Parent:FindFirstChild("Humanoid") --Find the human that touched the button
if check ~= nil then --If a human is found, then
local user = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touching human
local stats = user:findFirstChild("onPlayerAdded") --Find moneyholder
if stats ~= nil then --If moneyholder exists then
local Points = stats:findFirstChild("Points") --Get money
Points.Value = Points.Value +10 --increase amount of money by the number displayed here (500)
wait(.5) --wait-time before button works again
end
end
ting = 0 --remove debounce
end
end
script.Parent.Touched:connect(onTouched)
|