I'm new to scripting so I don't know how to do this ;-;
leaderboard script in ServerScriptService
game.Players.PlayerAdded:Connect(function(player) -- function activates when player joins local leaderstats = Instance.new("IntValue") leaderstats.Name = "leaderstats" leaderstats.Value = 0 leaderstats.Parent = player -- creates leaderstats into player local gold = Instance.new("IntValue") gold.Name = "Gold" gold.Value = 0 gold.Parent = leaderstats -- creates gold value in player end)
Kill script in weapon:
local goldgiven = 2 -- change to change amount -- of gold given per kill local tool = script.Parent -- the tool local handle = tool:WaitForChild("Handle") -- the handle or the part that the character sees local holding = false -- acts like a debounce tool.Equipped:Connect(function() -- function activates when player -- takes out tool holding = true -- sets holding to true end) tool.Unequipped:Connect(function() -- function activates when player -- unequips the tool holding = false -- sets holding to false end) handle.Touched:Connect(function(hit) -- activates when something touched the handle if hit.Parent:FindFirstChild("Humanoid") then -- if the thing that touched it has a humanoid -- it does this local hum = hit.Parent:WaitForChild("Humanoid") -- finds humanoid and waits for it to load if hum.Health == 0 then -- if the health of the entity it hit is 0 -- this happens if holding == true then -- the player has to be holding the tool -- or else the objective won't work and -- you have to switch up the variables local char = tool.Parent -- the character in the workspace local plr = game.Players:GetPlayerFromCharacter(char) -- takes the player in Players from the character local leaderstats = plr:FindFirstChild("leaderstats") -- finds leaderstats local gold = plr:FindFirstChild("Gold") -- finds gold if gold and leaderstats then -- if the player has the gold and leaderstats -- then this happens plr.leaderstats.gold.Value = plr.leaderstats.gold.Value + goldgiven -- gives player gold depending on the variable's (goldgiven) -- value. In this case it is 2 gold end end end end end)
Tell me in the comments if it doesn't work.