I made a damaging part for a simple sword I made and it doesn't seem to work

If you wanted it to do that, I would fire a remote event to another script that will remove health.

however it would work without using complicated remotes

also if you want to use remotes that are parented to replicatedstorage you would have to verify if the signal that the script recieved came from the player holding the tool

1 Like

You would have to put the players name in the function.

ye, a lot more complicated than just changing the kill script to a local script

I would keep it a server script.

sorry to ruin your fun but it stioll doesnt work

1 Like

please send a screnshot of the tool in workspace

local Damage = script.Parent.Parent.Parent.Damage.Value

function onTouched(hit)
    if hit:IsA("BasePart") then
	    local human = hit.Parent:findFirstChild("Humanoid")
	    if (human ~= nil) then
		    human.Health = human.Health - Damage
	    end
    end
end
script.Parent.Touched:connect(onTouched)

image_2022-07-05_231211034

I found the problem. Instead of script.Parent.Parent.Parent.Damage, do script.Parent.Damage.Value

local Damage = script.Parent.Damage.Value

function onTouched(hit)
    if hit:IsA("BasePart") then
	    local human = hit.Parent:findFirstChild("Humanoid")
	    if (human ~= nil) then
		    human.Health = human.Health - Damage
	    end
    end
end
script.Parent.Touched:connect(onTouched)

Ive fixed that in an earlier attempt.

Genuinely one of my typical problems, nobody can find the issue lol.

Is it possible to send me a place file so I can solve it?

copu.rbxl (59.3 KB)
that should work

1 Like

I would suggest not using .Touched and using raycasts

This should provide a good way to do it!

1 Like

You could just do Humanoid:TakeDamge(–insertamounthere)
After the part would touch a humanoid you would destroy it tooHumanoid:TakeDamage

I downloaded the place, and I got it to work for me, originally with remote events, but then without.
When I opened it, the main script for doing damage did not have the correct amount of .Parents.
Here is what it looked like:
local Damage = script.Parent.Damage.Value

Now in your original script (your screenshot on your first post) it seems you didn’t have .Value at the end of Damage. You said it didn’t appear to do anything though, so I’ll get to why in a second.

What I did to get it to work was just change
local Damage = script.Parent.Damage.Value
into
local Damage = script.Parent.Parent.Parent.Damage.Value

However, I don’t think the main script was actually the problem. In the local script, you enable and disable the script, but you cannot do that, so the script remains disabled.

What I think you’re trying to do is when the player equips the tool and clicks, they can deal damage for one second. First, enable the main script.

Originally, I put up an explanation of how I would go about doing this with remote events, but that led to several problems, so instead I did it a simpler way. (That’s why it’s edited)

In the local script, that plays the animation. We do not need it to do anything with other things other than playing the animation. So, just delete the stuff you do not need, and it should look like this:

Now, in the main script is where it should do damage. We can add a Boolean value to see if one second has passed, and if it has, we stop doing damage, and to start doing damage, all we have to do is connect the function the same way we did with the animation, making sure the value is true. Example:

End Result:

Sorry if this was a bit lengthy, this is my first post.

game:GetService(“RunService”).HeartBeat:Wait()
script.Parent.Touched:connect(onTouched)

Delaying the script for a single frame would yield no siginificant change.

disable the damagescript instead of changing can touch property

Better yet, just use a simple debounce technique (via a state variable or the tool’s ‘Enabled’ property).

also set the handle’s cantouch property to false

This would invalidate the purpose of the tool handle’s ‘Touched’ event/signal.

turn the kill script into a localscript

This is a very bad suggestion, damage checks should always be performed on the server.

actually no, when you change health property from a humanoid it dies for the server

This isn’t true, changes to a humanoid’s ‘Health’ property done on the client will not replicate to the server.

however it would work without using complicated remotes

RemoteObjects (remote events and/or remote functions) are not required and will only further bloat the codebase and increase instance dependency, a single isolated server script will suffice (no explicit network communication is required).