Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Character not valid member of workspace.terrain?

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

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.