Basically, I’ve been trying to make a touched script.
Now it works, but if you stay in your same position(hitbox touching the player), it won’t fire again?
Now in the output it states that it’s hitting the handle, but sometimes the touch event doesn’t fire at all.
I’ve tried disabling CanTouch on the handle but to no avail
Hitbox Script
local tool = script.Parent.Parent
local handle = tool:WaitForChild("Handle")
local stab = tool:WaitForChild("Stab")
-- Configurations
local config = script.Parent.Parent.Inact:WaitForChild("Configuration")
local kitchenknife = config:WaitForChild("KitchenKnife")
local animid = kitchenknife.Animation
local cd = kitchenknife.Cooldown
local damage = kitchenknife.Damage
local humdeb = false
tool.Activated:Connect(function()
stab.Touched:Connect(function(hit)
print(hit.Name)
if hit.Parent:FindFirstChild("Humanoid") and humdeb == false then
print("hum!")
humdeb = true
hit.Parent.Humanoid:TakeDamage(damage.Value)
task.wait(cd.Value)
humdeb = false
end
end)
end)
How would I fix this?
The part on the left is the hitbox
I provided a script, sorry I didn’t do that sooner
It makes sense that it doesnt fire anymore, because the char is not further moving (when not in animation) and with that, a new touch is not generated with the part. You should use Region3.
Another method you could use with .Touch is saving the plr in a table when he enters first and delete him out of the table when he left with .TouchEnded. Then just damage all plr in the loop.
local plrs = {}
script.Parent.Touched:Connect(function(touch)
if touch.Parent:FindFirstChild("Humanoid") and not table.find(plrs, touch.Parent.Name) then
table.insert(plrs, touch.Parent.Name)
repeat
touch.Parent.Humanoid:TakeDamage(10)
task.wait(1)
until
not table.find(plrs, touch.Parent.Name)
end
end)
script.Parent.TouchEnded:Connect(function(touch)
if touch.Parent:FindFirstChild("Humanoid") and table.find(plrs, touch.Parent.Name) then
table.remove(plrs, table.find(plrs, touch.Parent.Name))
end
end)
The damage on the plr is a bit inconsitent but that is like that when working with .Touched/TouchEnded
Same problem happens when I use the script, is this problem just impossible to fix with touched?
I’ve heard Region3 is very laggy and some people even call it trash.
Could you maybe suggest any other way to do it other than touched
Maybe this could help but as far as the Documentation says, Region3 is not depricated so it should work functionally. Anyway, there seems to be a method using OverlapParams. I never dealt with it so I cant say anything to it: OverlapParams | Documentation - Roblox Creator Hub
I am so glad you mentioned this! I completely forgot in one of my projects I’ve used params before, so I was able to copy that onto this script and get it to work!
Thank you