While loop not running even debugged

why does it not work i tried everything on my own end but still cannot work

it doesnt print worked

-- services
local RunService = game:GetService("RunService")

while true do
	RunService.Stepped:wait()
	print("worked")
	-- iterate through all the players and check if there distance to the magnitude is more then 150 or something
	for _, Player in pairs(game.Players:GetPlayers()) do
		if Player.Character then
			if Player.Character:FindFirstChild("Humanoid") and Player.Character:FindFirstChild("HumanoidRootPart") then
				local character = Player.Character
				local HumanoidRootPart = character.HumanoidRootPart
				local Baseplate = workspace.Baseplate
				
				HumanoidRootPart:GetPropertyChangedSignal("Position"):Connect(function()
					
					local Distance = (HumanoidRootPart.Position - Baseplate.Position).Magnitude
					local OldPosition = HumanoidRootPart.CFrame
					
					if Distance > 130 then
						HumanoidRootPart.CFrame = OldPosition
					end
				end)
			end
		end
	end
end

Highest probability that it doesn’t work is due to its directory in the game. Where is the script placed in?

server script service where all my stuff is

And what type of script was that?

server sided script i thought of doing magnitude instead of checking their jump power

I think because it is stuck on the Stepped event. Instead of a wait(), try connecting it with a function.

tried that and still doesnt work and i have another coroutine running either on another script

Some important notes:

@FracturedSoftware gave me this code

local LastData = {}

for _, Player in pairs(game:GetService("Players"):GetPlayers()) do
	if Player.Character then
		if Player.Character:FindFirstChildOfClass("Humanoid") and Player.Character:FindFirstChild("HumanoidRootPart") then
			local character = Player.Character
			local HumanoidRootPart = character.HumanoidRootPart
			local Baseplate = workspace.Baseplate
			if not LastData[Player.UserId] then
				LastData[Player.UserId] = {
					CFrame = Player.Character.HumanoidRootPart.CFrame,
					Tick = tick(),
				}
			end
			if (LastData[Player.UserId].Position - Player.Character.HumanoidRootPart.Position).Magnitude > Player.Character:FindFirstChildOfClass("Humanoid").WalkSpeed + 1 * (tick() - LastData[Player.UserId].Tick) then
				Player.Character:FindFirstChildWhichIsA("Humanoid").RootPart.CFrame = LastData[Player.UserId].CFrame
			else
				LastData[Player.UserId] = {
					CFrame = Player.Character.HumanoidRootPart.CFrame,
					Tick = tick(),
				}
			end
		end
	end
end

and i am trying to make a duplicate of it and make it like if its too far from the baseplate it would instantly kick you or move back

:GetPropertyChangedSignal does not work for things that are updated with physics and so it isn’t updating when the players position is changed.

ok i used another method that doesnt even work its like the other code i gave

-- iterate through all the players and check if there distance to the magnitude is more then 150 or something
for _, Player in pairs(game.Players:GetPlayers()) do
	if Player.Character then
		if Player.Character:FindFirstChildOfClass("Humanoid") and Player.Character:FindFirstChild("HumanoidRootPart") then
			print("worked")
			local character = Player.Character
			local Humanoid = character.Humanoid
			local HumanoidRootPart = character.HumanoidRootPart
			local Baseplate = workspace.Baseplate
			local OldPos = HumanoidRootPart.CFrame
			
			if not JumpData[Player.UserId] then
				JumpData[Player.UserId] = {
					CFrame = HumanoidRootPart.CFrame;
					Tick = tick()
				}
			end
			if (JumpData[Player.UserId].Position - Baseplate.Position).Magnitude >= 130 * (tick() - JumpData[Player.UserId].Tick) then
				HumanoidRootPart.CFrame = OldPos
			else
				JumpData[Player.UserId] = {
					CFrame = HumanoidRootPart.CFrame;
					Tick = tick()
				}
			end
		end
	end
end

no method of getting magnitude its still doesnt work i would have to get a better method i dont think that raycasting is possible unless i just make a part that kicks them :stuck_out_tongue:

I don’t believe using RunService’s RenderStepped event is a good idea, if you aren’t making any expensive actions like customizing or changing how the camera works in your game. Instead, use the Heartbeat event. It can also fire every 1/60 of a frame, the same like RenderStepped, and it also returns what we call deltatime.

If you don’t know about it, you can check about it here.

But hey, it’s Roblox! Hence the title Powering Imagination that they mostly encourage in Roblox, so you do you! It’s your game, almost anything is possible. Go get 'em tiger! :wink:

RunService.Stepped:Wait() only works on the client, I’m pretty sure.

Could you change the first line of the loop to RunService.Heartbeat:Wait() or RunService.RenderStepped:Wait() -- Only if this is a local script

It doesn’t only work on client, all of the RunService events are functional on both sides. They are all three the same but only has a difference in a small marginal of time. It’s all in the task scheduler.