Hey i need help please.

local Players = game:GetService("Players")
local DataStore = game:GetService("DataStoreService")
local ds2 = DataStore:GetDataStore("PointsSaveSystem")

Players.PlayerAdded:Connect(function(plr)
	local Redeeemed = Instance.new("BoolValue",plr)
	Redeeemed.Name = "Used"
    Redeeemed.Value = ds2:GetAsync(plr.UserId) or false
    ds2:SetAsync(plr.UserId, Redeeemed.Value)
    
	local leaderstats = Instance.new("Configuration", plr)
	leaderstats.Name = "leaderstats"
	
    local Coins = Instance.new("IntValue", leaderstats)
    Coins.Name = "Coins"
    Coins.Value = ds2:GetAsync(plr.UserId) or 0
	ds2:SetAsync(plr.UserId, Coins.Value)
	
	Redeeemed.Changed:Connect(function()
		ds2:SetAsync(plr.UserId, Redeeemed.Value, Coins.Value)
	end)
	
	Coins.Changed:Connect(function()
		ds2:SetAsync(plr.UserId, Redeeemed.Value, Coins.Value)
	end)
end)

Players.PlayerRemoving:Connect(function(plr)
	local Used = plr:FindFirstChild("Used")
	local Coins = plr:FindFirstChild("leaderstats"):WaitForChild("Coins")
	ds2:SetAsync(plr.UserId, Used.Value, Coins.Value)
end)

3 comments

0

Errors?

0

there isn't error.

0

You shouldn't use WaitForChild on PlayerRemoving lol. Also, The parent argument to Instance.new is deprecated, assign the parent as last property.