The code below goes into the enemies, it gives the killer gold and xp. But I don't know how to make it know who killed it.
local gold = script.Parent.Config.Gold.Value
local exp = script.Parent.Config.XP.Value
local Humanoid = script.Parent.Humanoid
function PwntX_X()
local tag = Humanoid:findFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local Leaderstats = tag.Value:findFirstChild("leaderstats")
if Leaderstats ~= nil then
Leaderstats.Gold.Value = Leaderstats.Gold.Value + gold
wait(0.1)
script:remove()
end
end
end
end
Humanoid.Died:connect(PwntX_X)
This script is the damage script in the handle of the weapon used to kill the victim. If you know how to write it so it connects with the gold/exp script I would be very grateful.
dmg = script.dmg.Value
function touch(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health - dmg
script.Disabled = true
end
script.Parent.Touched:connect(touch)
And the following script is something I got from the roblox paintball gun paintball script. I tried putting it inside the damage script and it didn't work.
function tagHumanoid(humanoid)
-- todo: make tag expire
local tag = script.Parent:findFirstChild("creator")
if tag ~= nil then
local new_tag = tag:clone()
new_tag.Parent = humanoid
end
end
function untagHumanoid(humanoid)
if humanoid ~= nil then
local tag = humanoid:findFirstChild("creator")
if tag ~= nil then
tag.Parent = nil
end
end
end

4 comments
Basically log in the attacks into the server, and the last one weapon that touched the victim will be logged in the server.
Would that work if the weapon is destroyed as soon as it hits the victim? I'm also using projectiles.
@Edbotikx, don't use deprecated code and please make your function(in the first code snippet) have its name be relevant to what you are coding
Actually I decided to use my brain. I will make it so that when a weapon hits the victim, it will change a object value in the victim to the object value of the attacker. And when the victim dies it will get the player from the character. I think that should work.