I want to make it so that when an enemy is detected the person who killed it will be rewarded money, but I don’t know how to do that. Here is the leaderboard and datastore script that I used:
DataStore :
local datastore = game:GetService("DataStoreService"):GetDataStore("leaderstats")
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrkey = "id_"..plr.userId
local savevalue = plr.leaderstats.Cash
local savevalue2 = plr.leaderstats.Minutes
local GetSaved = datastore:GetAsync(plrkey)
if GetSaved then
savevalue.Value = GetSaved[1]
savevalue2.Value = GetSaved[2]
else
local NumbersForSaving = {savevalue.Value, savevalue2.Value}
datastore:GetAsync(plrkey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
datastore:SetAsync("id_"..plr.userId, {plr.leaderstats.Cash.Value, plr.leaderstats.Minutes.Value})
end)
leaderstats:
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local player = game:GetService("Players")
local Cash = Instance.new("IntValue", leaderstats) -- Create a score variable
Cash.Name = "Cash" -- Name
Cash.Value = 150 -- Initial Value
game.StarterGui.BasicUI.Money.Text = Cash.Value .. "$"
player.CharacterAdded:Connect(function(char)
char.Humanoid.Died:Connect(function(Died)
local creator = char.Humanoid:FindFirstChild("creator")
local leaderstats = creator.Value:FindFirstChild("leaderstats")
if creator~=nil and creator.Value ~= nil then
Cash.Value += math.random(200 , 600)
end
end)
end)
end)
I want to make for every enemy but each enemy rewards you different amounts.
Also, i dont know how to create “CreatorTags” because i am new to roblox studio. Please respond.