I’m trying to make a sword that gives you points for every player you kill, while researching, I found something called “creator tags” in most of Roblox’s gears. I understand what it does but what I want to do is figure out how to implement it in my sword.
local Damage = script.Parent.Values.Damage.Value
local tool = script.Parent
local Trail = script.Parent.Trail
local idleAnim = script.Animations:WaitForChild("Idle")
local idleAnimTrack
local swingAnim = script.Animations:WaitForChild("Swing")
local swingAnimTrack
local swingAnim = script.Animations:WaitForChild("Swing")
local slashSound = script:WaitForChild("SlashSound")
local sheathSound = script:WaitForChild("SheathSound")
local hitSound = script:WaitForChild("HitSound")
local hitCharacters = {}
local debounce = false
function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = player
Debris:AddItem(Creator_Tag, 2)
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
tool.Equipped:Connect(function()
local humanoid = script.Parent.Parent.Humanoid
if not idleAnimTrack then idleAnimTrack = humanoid:LoadAnimation(idleAnim) end
idleAnimTrack:Play()
sheathSound:Play()
end)
tool.Unequipped:Connect(function()
if idleAnimTrack then idleAnimTrack:Stop() end
if swingAnimTrack then swingAnimTrack:Stop() end
sheathSound:Play()
end)
tool.Activated:Connect(function()
if debounce then return end
debounce = true
local humanoid = script.Parent.Parent.Humanoid
if not swingAnimTrack then swingAnimTrack = humanoid:LoadAnimation(swingAnim) end
swingAnimTrack:Play()
wait(0.3)
Trail.Enabled = true
slashSound:Play()
wait(0.2)
Trail.Enabled = false
wait(0.5)
debounce = false
end)
tool.Hit.Touched:Connect(function(touch)
if hitCharacters[touch.Parent] or not debounce then return end
if touch.Parent:FindFirstChild("Humanoid") then
hitSound:Play()
touch.Parent.Humanoid:TakeDamage(Damage)
hitCharacters[touch.Parent] = true
wait(1)
hitCharacters[touch.Parent] = nil
end
end)