Basically i just want to add creator tag so i can add a kill point for my sword but i don’t know how to add creator tag value to player here script local Debris = game:GetService(“Debris”)
local damage = 10
local debounce = true
local tool = script.Parent
Players = game:GetService(“Players”)
function tagHumanoid(hum, player)
if hum and hum:IsA(“Humanoid”) then
local existingTag = hum:FindFirstChild(“creator”)
if existingTag then
existingTag:Destroy()
end
local tag = Instance.new("ObjectValue")
tag.Name = "creator"
tag.Value = player
Debris:AddItem(tag, 2)
tag.Parent = hum
end
end
function attack(Player)
print(“attack function called”)
local hitbox = script.Parent
hitbox.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid and debounce then
humanoid:TakeDamage(damage)
local character = hit.Parent
local player = Players:GetPlayerFromCharacter(character)
print("damaged humanoid by " .. damage)
tagHumanoid(humanoid, Player)
debounce = false
wait(1)
debounce = true
end
end)
end
script.Parent.Parent.Activated:Connect(function()
local success, err = pcall(function()
end)
if success then
attack()
end
end)
script.Parent.Parent.Activated:Connect(function()
local success, err = pcall(function()
end)
if success then
attack()
end
end)
You’re not passing an argument when you call attack(), so Player inside the attack() function is nil, which is being sent to the tagHumanoid() function.
And was it intentional that you typed script.Parent.Parent.Activated instead of script.Parent.Activated or tool.Activated when you defined tool as script.Parent, not script.Parent.Parent?
You are also using script.Parent for hitbox inside of the attack() function:
local function attack(Player)
print("attack function called")
local hitbox = script.Parent
-- ...
end
local Debris = game:GetService(“Debris”)
local damage = 10
local debounce = true
local tool = script.Parent
Players = game:GetService(“Players”)
function tagHumanoid(hum, player)
if hum and hum:IsA(“Humanoid”) then
local existingTag = hum:FindFirstChild(“creator”)
if existingTag then
existingTag:Destroy()
end
local tag = Instance.new("ObjectValue")
tag.Name = "creator"
tag.Value = player
Debris:AddItem(tag, 2)
tag.Parent = hum
end
end
function attack(Player)
print(“attack function called”)
local hitbox = script.Parent
hitbox.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid and debounce then
humanoid:TakeDamage(damage)
local character = hit.Parent
local player = Players:GetPlayerFromCharacter(character)
print("damaged humanoid by " .. damage)
tagHumanoid(humanoid, Player)
debounce = false
wait(1)
debounce = true
end
end)
end
script.Parent.Parent.Activated:Connect(function()
local success, err = pcall(function()
end)
if success then
attack()
end
end)