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 Model?

Asked by
Storche 13
4 years ago

I've made a box that spawns infront of the player and damages any other players, however instead of damaging players I just get this error: "TakeDamage is not a valid member of Model"

local HB = game.ServerStorage.HB1:WaitForChild("H1")
            local Character = player.Character
            local Hitb = HB:Clone()
            Hitb.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-5)
            Hitb.Parent = workspace

            Touch = Hitb.Touched:connect(function(hit)
                if hit.Parent:FindFirstChild("Humanoid") then
                    if hit.Parent.Name ~= player.Name then
                        hit.Parent:TakeDamage(15)
                        if Touch ~= nil then Touch:Disconnect() end
                        Hitb:Destroy()
                    end
                end
            end)
0
It might be because you're doing hit.Parent:TakeDamage(15), and what it looks like, that is refering to the Character, not the players humanoid. I could be wrong. ToastyWarmBread 54 — 4y
0
I'd also like to recommend you use FindFirstChildOfClass("Humanoid") just to make sure that what you are trying to damage is, in fact, a Humanoid Despayr 505 — 3y

1 answer

Log in to vote
2
Answered by 4 years ago

You did hit.Parent which is just the Character. You have to do hit.Parent.Humanoid:TakeDamage(15)

Ad

Answer this question