This is my DataStore 2, but it is not working, and I am not sure what I did wrong. Please help! It is supposed to save the gold and update and give money when you kill another player.
game.Players.PlayerAdded:Connect(function(plr)
local dataGold = DataStore2("Gold", plr)
local folder = Instance.new("Folder",plr)
folder.Name = "leaderstats"
local gold = Instance.new("IntValue", folder)
gold.Name = "Gold"
local initialGold = 100
gold.Value = dataGold:Get(initialGold)
gold.Changed:Connect(function()
dataGold:Set(gold.Value)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local stats = tag.Value:WaitForChild("leaderstats")
stats["Gold"].Value = stats ["Gold"].Value + 150
end
end
end)
Oh sorry I did the wrong code I think, but this doesn’t work still.
local DataStore2 = require(1936396537)
DataStore2.Combine("MasterKey","Gold")
game.Players.PlayerAdded:Connect(function(plr)
local dataGold = DataStore2("Gold", plr)
local folder = Instance.new("Folder",plr)
folder.Name = "leaderstats"
local gold = Instance.new("IntValue", folder)
gold.Name = "Gold"
local initialGold = 100
gold.Value = dataGold:Get(initialGold)
gold.Changed:Connect(function()
dataGold:Set(gold.Value)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local stats = tag.Value:WaitForChild("leaderstats")
stats["Gold"].Value = stats ["Gold"].Value + 150
end
end
end)
Why use creator inside of the character’s humanoid, (Assuming it’s not being found due to the event firing right when the player dies), when you could just use game.Players:GetPlayerFromCharacter?
King_Deadly has a point, just noticed that you were looking for the creator inside the humanoid, you can just store it somewhere in the characters or anywhere in the player, for example:
Don’t forget you can also use the humanoid function, died and use it so when that player dies the killer gets gold.
Don’t also forget to add a script where you’ll change the killed user’s stringvalue inside the kill script for a weapon so you’d have the kill and you’ll get money.
Correct the example image i made, i meant “stringvalue” not “numbervalue”.