Not sure but I think you have to do this way differently. I would do something like
local hum = script.Parent.Humanoid
hum.Died:Connect(function(player)
player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 10
player.leaderstats.Experience.Value = player.leaderstats.Experience.Value + 3
end)
But make sure the leaderstats actually exists.
Something similar to that.
If it doesn't work I think you need to add some script to the weapon to find the player who killed the NCP.
If it's a player, not an NCP then try putting the script in startercharacterscripts. Otherwise, you need to add some code to the weapon.
Edit: Use this kind of leaderstats
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "leaderstats"
local Cash = Instance.new("IntValue",leader)
Cash.Name = "Cash"
Cash.Value = ds:GetAsync(player.UserId) or 0
ds:SetAsync(player.UserId, Cash.Value)
Cash.Changed:connect(function()
ds:SetAsync(player.UserId, Cash.Value)
end)
end)
7 comments
okay, i will try this. I used creator because its said to specify who killed someone
Doesnt work, sorry mate. "Attempted to index nil with leaderstats" Even though i have stats loaded.
Make sure all the lines are correct and try making some script in the weapon. Also make sure your leaderstats exists and is named what is there.
Try using this kind of leaderstats script
Try using this kind of leaderstats script
@cancle5 I have style of script like that already. I need to save four leaderstats which I already am doing, I don’t think yours would change anything.
@cancle5 I have style of script like that already. I need to save four leaderstats which I already am doing, I don’t think yours would change anything.