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

Character not valid member of workspace.terrain?

Asked by 2 years ago

I am getting an error in my punch script that says: Character is not a valid member of Terrain "Workspace.Terrain"
not sure how to fix this, but it might be because the characters I am using are R15 and I am also using the terrain feature.

Here is the server script where I am getting the error

game.ReplicatedStorage.Remotes.Punch.OnServerEvent:Connect(function(player, damage)
    for i, Target in pairs(game.Workspace:GetDescendants()) do
        if Target.Name ~= player.Name then
            if(Target.Character.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude < 5 then
                Target.Character.Humanoid.Health -= damage
            end
        end
    end
end)

1 answer

Log in to vote
0
Answered by 2 years ago

You need to filter out the Target, you are currently including everything in the workspace except your own character, and obvious Terrain doesn’t have a character.

Just replace line 3 with something like

if Target.Name ~= player.Name and Target:FindFirstChildWhichIsA(‘Humanoid’) then

This checks for if the Target has Humanoid inside.

Also, Target most likely do not have an instance called Character inside, so consider just doing Target.HumanoidRootPart and Target.Humanoid instead.

Ad

Answer this question