Jail script help!

I printed mag before the while loop and it printed 0.

No print in in the while loop.

It printed below while loop and below wait(60) seconds but the print inside of the mag does not work.

This might be since your mag variable is never being updated, try putting the variable after the wait inside the loop.

game.Players.PlayerAdded:Connect(function(player)

	local playerID = player.UserId

	local jailed
	local success, errormessage = pcall(function()
		jailed = jailData:GetAsync(playerID)
	end)

	if jailed and success then
		table.insert(jail, player)
		if table.find(jail, player) then
			game.Workspace:FindFirstChild(player.Name):WaitForChild("HumanoidRootPart").Position = game.Workspace:FindFirstChild("Torment").Position
			while true do
				wait(60)
                local mag = (game.Workspace:FindFirstChild("Torment").Position - game.Workspace:FindFirstChild(player.Name).HumanoidRootPart.Position).Magnitude
				if mag > 15 then
					game.Workspace:FindFirstChild(player.Name).HumanoidRootPart.Position = game.Workspace:FindFirstChild("Torment").Position
				end
			end
		end
	end
end)
1 Like

But mag is already defined though?

Because your basically checking if the same magnitude is over 15, Iā€™m not sure if it because of that but you can give it a try.

Works! Though what is wrong with the first script though? Thanks!