So I’m making a script where if the player kills somebody the player gets money but the script makes it so if the player kills the other player. the other player is the person that gets the money instead of the player that killed him. this is my script:
wait(.5)
local plr = script.Parent.Parent.Parent
local char = plr.Character
local idle = char.Humanoid:LoadAnimation(script.Animations.Idle)
local equipped = false
local attacking = false
local RaycastHitbox = require(game.ServerScriptService.RaycastHitboxV2)
local Hitbox = RaycastHitbox:Initialize(script.Parent.Weapon)
durability = 15
local attack1 = char.Humanoid:LoadAnimation(script.Animations.Attack1)
local broken = false
function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = player
game:GetService("Debris"):AddItem(Creator_Tag, .5)
Creator_Tag.Parent = humanoid
end
function UntagHumanoid(humanoid)
for i, v in pairs(humanoid:GetChildren()) do
if v:IsA("ObjectValue") and v.Name == "creator" then
v:Destroy()
end
end
end
Hitbox.OnHit:Connect(function(hit, humanoid)
if humanoid.Parent ~= char and humanoid.Parent.Handler.Infected.Value == true then
script.Parent.Weapon.Hit:Play()
local damage = math.random(30,45)
local Players = game:GetService("Players")
local character = hit.Parent
local Player = Players:GetPlayerFromCharacter(character)
local humanoid = character:FindFirstChildOfClass("Humanoid")
local Speed = 25
local Force = 40000
local TotalForce = Force
local KnockBack = Instance.new("BodyVelocity",hit.Parent:FindFirstChild("Torso"))
KnockBack.MaxForce = Vector3.new(TotalForce,TotalForce,TotalForce)
KnockBack.Velocity = plr.Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * Speed -- based on the direction YOUR character is facing.
game.Debris:AddItem(KnockBack,0.1)
UntagHumanoid(humanoid)
TagHumanoid(humanoid, Player)
humanoid:TakeDamage(damage)
humanoid.Parent.Actions.Stunned.Value = true
if durability == 0 then
Hitbox:HitStop()
script.Parent.Weapon.Transparency = 1
script.Parent.Weapon.B:Play()
script.Parent.Weapon.ParticleEmitter:Emit(50)
game.ReplicatedStorage.EditGUI:FireClient(plr,"text","Your baseball bat broke.")
broken = true
idle:Stop()
attack1:Stop()
wait(1.5)
script.Parent:Destroy()
end
durability = durability - 1
end
end)