Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

TakeDamage is not a valid member of Part ??

Asked by 4 years ago
Edited 4 years ago

Hi, i don't understand why i keep getting this error. I'm trying to make a script where you deal 10 damage when touching a part.

local Main = script.Parent

Main.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit:TakeDamage(10)
    end
end)

Also the script is inside a model as you can see here: (http://i.imgur.com/Hq4jPvJ.png)

The model contains a humanoid because i want it to display a name above it.

1 answer

Log in to vote
0
Answered by 4 years ago

Take Damage only works with a humanoid. You've done it with a part so it won't work. So you'll have to change hit:TakeDamage to hit.Parent:FindFirstChild("Humanoid"):TakeDamage 10, also I recommend maybe using a debounce system, as the touched event fires multiple times.

0
Sorry im on mobile so it may not look right idrk JeffTheEpicRobloxian 258 — 4y
0
It worked! I appreciate your help. HeisukeKexji 8 — 4y
0
np glad i could help JeffTheEpicRobloxian 258 — 4y
Ad

Answer this question