Teleport script not working correctly

The last guy didn’t really solve my problem, but during that time i made slight adjustments to the code, as it previously looked like this:

local player = game.Players.LocalPlayer.PlayerCharacter
while true do
	player.Position = player.Position + Vector3.new(Random, Random, Random)
if
	game.StarterGui.ScreenGui.Stop.MouseButton1Click
then
	break
end

	game.StarterGui.ScreenGui.Stop.MouseButton1Click:Connect()
	end

Updated version looks like this:

local button = script.Parent
local player = game.Players.LocalPlayer
button.MouseButton1Click:Connect(function(player)
if	button.MouseButton1Click then
	player.HumanoidRootPart.Position = player.HumanoidRootPart.Position + Vector3.new(-159.99, -24.118, -59.804)
	print "Imprisoned"
	end
	end)

For some reason this new code outputs weird error message in the output and refuses to work(By the way, if i try to add .Character , it outputs exact same thing, but with said instance):

Events don’t work like that: you need to Connect the event to a function, and in this case have that function set a variable that the while loop is able to access.

For this code specifically, you have to connect to the Player’s specific Stop button.
I’m not sure if PlayerCharacter is something you created and Parented to the Player in another, script, but I assume you meant Player.Character

Something like this might work:

local player = game.Players.LocalPlayer
local stopped = false

player.PlayerGui.ScreenGui.Stop.MouseButton1Click:Connect(function()
    stopped = true
end)

while not stopped do
    player.Character.HumanoidRootPart.Position = player.Character.HumanoidRootPart.Position + Vector3.new(math.random(1,200), math.random(1,200), math.random(1,200))
end