Scripting help coroutine.wrap

Script:

local players = game:GetService("Players")
local jumpparts = game.Workspace.JumpParts
game.ReplicatedStorage.PlayerEvents.Jump.OnServerEvent:Connect(function(x,plr)
	for a,b in pairs(jumpparts:GetChildren()) do
		for i,v in pairs(players:GetPlayers()) do		
             coroutine.wrap(function()
					if plr:WaitForChild("Jumped").Value == true then	
					local character = v.Character or v.CharacterAdded:Wait()
					local humanoidRootpart = character:WaitForChild("HumanoidRootPart")
					if (b.Position - humanoidRootpart.Position).magnitude < 50 then -- this distance for test.
						warn("INRANGE")
					end
					end
			end)()
	  end
	end	
end)

my problem: this script takes the script.

jumpparts

Error: Workspace.JumpParts.Script:6: Position is not a valid member of Script “Workspace.JumpParts.Script”

There’s a script in JumpParts, and you’re getting all the children in JumpParts with no filtering, so it’s getting the script and trying to get the position property form it, check if it’s a BasePart before doing anything else

1 Like

You’re looking at all the children. The Script is one of the children.

You assume b is a BasePart, but it can also be a Script.

Check that the child b:IsA("BasePart") before you do anything.

1 Like