-- can't workout what i've done wrong...........
local DataStoreService = game:GetService ("DataStoreService") local GameData = DataStoreService:GetDataStore("storeroom")
game.Players.PlayerAdded:connect (function(player) local stats = Instance.new("IntValue", player) stats.Name = "leaderstats"
local cash = Instance.new("IntValue", stats)
cash.Name = "Cash"
cash.Value = 0
local rank = Instance.new("StringValue", stats)
rank.Name = "Rank"
rank.Value = "Private"
local key = "player_"..player.UserId
local savevalues = GameData:GetAsync(key)
if savevalues then
cash.Value = savevalues[1]
rank.Value = savevalues[2]
else
local valuestosave = {cash.Value, rank.Value}
GameData:SetAsync (key, valuestosave)
end
end)
game.Players.PlayerRemoving:connect (function(player)
local key = "player_"..player.UserId
local savevalues = GameData:GetAsync(key)
local valuestosave = {player.leaderstats.Cash.Value, player.leaderstats.Rank.Value}
GameData.SetAsync (key, valuestosave)
end)
secondly in a part i have the following script:-
enabled = true
script.Parent.Touched:connect (function(hit) local human = hit.Parent:FindFirstChild("Humanoid")
if human then
local player = game.Players:GetPlayerFromCharacter (hit.Parent)
player.leaderstats.Cash.Value = 100
player.leaderstats.Rank.Value = "General"
wait(2)
enabled = false
end
end)

1 comment
thank you so much for your time. it now works