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

player is not a valid member of datamodel 1?

Asked by 4 years ago

Player is not a valid member of datamodel 1. I check the code a-lot of times and can't see the problem. Please tell me what I need to change. Btw I was making a save system. Please check this code and see what the problem.

Script:

local dataStores = game:GetService("DataStoreService"):GetDataStore("ItenseDataStore") local defaultPoints = 10 local playerLeft = 0 player = game.Players.LocalPlayer

game.Players.PlayerAdded:Connect(function(player)

playerLeft = playerLeft + 1

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local points = Instance.new("IntValue")
points.Name = "Points"
points.Value = 0
points.Parent = leaderstats

local val = Instance.new("IntValue")
val.Name = "Wins"
val.Value = 0
val.Parent = leaderstats

local player_data

pcall(function()
    player_data = dataStores:GetAsync(player.UserId.."-Points")
end)

if player_data ~= nil then points.Value = player_data else --New Player points.Value = defaultPoints

end

end)

local bindableEvent = Instance.new("BindableEvent")

game.Players.PlayerRemoving:Connect(function(player) pcall(function() dataStores:SetAsync(player.UserId.."-Points",player.leaderstats.points.Value) print("Saved") playerLeft = playerLeft - 1 bindableEvent:Fire() end)

end)

game:BindToClose(function()

while playerLeft > 0 do
    bindableEvent.Event:Wait()
end

end)

0
Please format User#30567 0 — 4y
0
Also which line is the error pointing to? User#30567 0 — 4y
0
^^ mightydifferent 85 — 4y

Answer this question