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

How to fix Humanoid is not a valid member of Accessory?

Asked by 2 years ago
Edited 2 years ago

I am trying to make a teleport pad and keep getting this error. How can I fix?

local Pad2 = game.Workspace.TeleportPad2

script.Parent.Touched:Connect(function(touchPart)

if touchPart and touchPart.Parent and touchPart.Parent.Humanoid and

touchPart.Parent.currentlyTeleporting.Value == false then

local Character = touchPart.Parent

local teleportLocation = CFrame.new(Pad2.CFrame.X, Pad2.CFrame.Y + 5, Pad2.CFrame.Z)

Character:SetPrimaryPartCFrame(teleportLocation)

    local teleportingValue = Character.currentlyTeleporting
    teleportingValue.Value = true
    wait(3)
    teleportingValue.Value = false
end

end)

1 answer

Log in to vote
0
Answered by 2 years ago

I think I might know what the problem is here. The script might be better to look more like this:

local Pad2 = game.Workspace.TeleportPad2

script.Parent.Touched:Connect(function(touchPart)
    local Humanoid = touchPart.Parent:FindFirstChild("Humanoid")
    if touchPart and touchPart.Parent and Humanoid and touchPart.Parent.currentlyTeleporting.Value == false then

        local Character = touchPart.Parent

        local teleportLocation = CFrame.new(Pad2.CFrame.X, Pad2.CFrame.Y + 5, Pad2.CFrame.Z)

        Character:SetPrimaryPartCFrame(teleportLocation)

        local teleportingValue = Character.currentlyTeleporting
         teleportingValue.Value = true
        wait(3)
         teleportingValue.Value = false
    end
end)

What has been changed?

  • I have replaced and touchPart.Parent.Humanoid in line 5 with Humanoid. to check if the humanoid from the line I added at line 4 local Humanoid = touchPart.Parent:FindFirstChild("Humanoid") simply trying to get it, returning nil if nothing is there exists.

What is this doing?

  • This is checking to make sure that it can actually find a item called Humanoid. In your code its just telling it where the Humanoid is meant to be.
0
Thanks it works man. You the goat Christian_Name 7 — 2y
Ad

Answer this question