I have a sword script that deals damage and give points to a player but it doesn’t work. I tried copying the roblox sword model to make the creator thing. I have tried everything like adding print to know what happened etc. Heres the code local Debris = game:GetService(“Debris”)
local damage = 10
local debounce = true
function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new(“ObjectValue”)
Creator_Tag.Name = “creator”
Creator_Tag.Value = player
Debris:AddItem(Creator_Tag, 2)
if humanoid then
Creator_Tag.Parent = humanoid
end
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
function attack(hit)
print(“attack function called”)
if hit and hit.Parent:FindFirstChild(“Humanoid”) and debounce then
hit.Parent.Humanoid:TakeDamage(damage)
print("damaged humanoid by " … damage)
UntagHumanoid(hit.Parent.Humanoid)
TagHumanoid(hit.Parent.Humanoid)
wait(0.01)
debounce = false
wait(1)
debounce = true
end
end
script.Parent.Parent.Activated:Connect(function()
local success, err = pcall(function()
attack()
end)
if not success then
print("Error: " … err)
print(debug.traceback())
end
end)
Shouldn’t you put if success then attack()end?
I forgot about that but now I have added that to my code it does not damage at all and print(“damaged humanoid by”)
You use “hit” in the attack() but don’t pass the hit parameter when you call it
1 Like
script.Parent.Parent.Activated:Connect(function()
local success, err = pcall(function()
attack(script.Parent)
end)
if not success then
print("Error: " … err)
print(debug.traceback())
end
end)
So like this?
Thanks it worked one problem tho it doesnt work with my kill for cash that works with creator
Why is there a objectValue in the humanoid?
because of my script that give money when killing is local tag = Humanoid:findFirstChild("creator")
Again the tagHumanoid() function doesn’t pass the parameter when called
1 Like
I don’t get this one now is it like this?
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)
print("damaged humanoid by " … damage)
UntagHumanoid(humanoid)
TagHumanoid(humanoid, player)
debounce = false
wait(1)
debounce = true
end
end)
end
Is it not working or did you not test it yet?
Maybe change the objectValue to a intValue and make it’s value to a number?
It still doesnt work (thanks for the help though)