Problem with teleporting a player (no errors)

Hello, I am once again asking for your scripting support.

I am making a handcuff script with a cuff and jail function, everything else works but the teleportation part to the prison. I have been trying everything I know to try to fix it, but I can’t get it to work.

Here is my server script (This is only a part of it):

local prisons = workspace.Prison:GetChildren()
JailRemote.OnServerEvent:Connect(function(player, state, targetplayer) -- state == 'Jail' and targetplayer == workspace.Player1  
	if state == 'Jail' then
		local GetPlayer = game.Players:FindFirstChild(targetplayer.Name)
		targetplayer.HumanoidRootPart.Position = prisons[math.random(1,#prisons)].Position -- There are no errors and it just proceeds to the next line 
		GetPlayer.TeamColor = BrickColor.new("Smoky grey")
	end
end)

I have tried with “SetPrimaryPartCFrame” but it just does the same thing. I researched for 3 days about this and tried everything, but most of it just did the same thing as it does now.

No errors at all? Maybe try adding some prints to see where it breaks?

local prisons = workspace.Prison:GetChildren()
JailRemote.OnServerEvent:Connect(function(player, state, targetplayer) -- state == 'Jail' and targetplayer == workspace.Player1  
        print("State: "..state)
	if state == 'Jail' then
		local GetPlayer = game.Players:FindFirstChild(targetplayer.Name)
        local jailPosition = prisons[math.random(1,#prisons)].Position     
        print(jailPosition)
		targetplayer.HumanoidRootPart.Position =  jailPosition -- There are no errors and it just proceeds to the next line 
		GetPlayer.TeamColor = BrickColor.new("Smoky grey")
	end
end)

I tried putting prints but the script “runs as it should”

script:

JailRemote.OnServerEvent:Connect(function(player, state, targetplayer)
	print("State "..state)
	if state == 'Jail' then
		local GetPlayer = game.Players:FindFirstChild(targetplayer.Name)
		local jailPosition = prisons[math.random(1,#prisons)].Position
		print(jailPosition)
		targetplayer.HumanoidRootPart.Position = jailPosition
		print("Hello")
		GetPlayer.TeamColor = BrickColor.new("Smoky grey")
	end
end)

image

1 Like

It worked for me when I changed the HumanoidRootPart.Position. I don’t know what’s different about your game. The only thing I can think of is that the jail’s position is a very long decimal point, maybe that is causing the problem? Maybe try setting the position to a rounder number.

JailRemote.OnServerEvent:Connect(function(player, state, targetplayer)
	print("State "..state)
	if state == 'Jail' then
		local GetPlayer = game.Players:FindFirstChild(targetplayer.Name)
		local jailPosition = prisons[math.random(1,#prisons)].Position
		print(jailPosition)
		targetplayer.HumanoidRootPart.Position = Vector3.new(100,10,10) --For testing purposes
		print("Hello")
		GetPlayer.TeamColor = BrickColor.new("Smoky grey")
	end
end)

You can use Model:MoveTo

you can change targetplayer.HumanoidRootPart.Position = Position to target:MoveTo(Position)

In the script there are no errors, but i tried to run it on the server in the commandbar and it gave me this error: Unable to cast double to Vector3

This was the command: game.Players.Player2.Character:MoveTo(-14.8809662, 3.94642305, 39.9111366)

The position parameter needs to be a Vector3 value. This is how you should write it:

game.Players.Player2.Character:MoveTo(Vector3.new(-14.8809662, 3.94642305, 39.9111366))

That works in the commandbar, but not in the script.

I didn’t think that this localscript would have anything to do with it, but here it is if it helps:

local Jailing = false
local Using = false
local PlayerCuffed -- On a client event the script changes this to the player being cuffed which is equal to workspace.Player1
Tool.Unequipped:Connect(function()
	Player.PlayerGui.CuffGui.Enabled = false
	if PlayerCuffed == nil then return end
	Using = false
	if not Jailing then
		RemoteEvent:FireServer('UnCuff', PlayerCuffed)
		PlayerCuffed = nil
	end
end)

CuffGui.Jail.JailRound.JailButton.MouseButton1Down:Connect(function()
	Jailing = true
	local humanoid = Player.Character:FindFirstChildOfClass('Humanoid')
	if humanoid then
		humanoid:UnequipTools()
	end
	Using = false
	RemoteEvent:FireServer('Jail', PlayerCuffed)
	PlayerCuffed = nil
	Jailing = false
end)

This is a part of my localscript in the cuffs.

Could you confirm that PlayerCuffed is a character instance? And not a player instance or some sort?

Sorry forgot, but the PlayerCuffed is equal to workspace.Player1

Does this part of your script works?

If so, you could just try instead of using the targetplayer directly, maybe do GetPlayer.Character.HumanoidRootPart.Position = jailPosition?

There are no errors in the console when I changed it to this. And the script goes to the next line

You need to put Vector3.new()

game.Players.Player2.Character:MoveTo(Vector3.new(-14.8809662, 3.94642305, 39.9111366) )

This was mentioned before by astra_wr.

I researched a little more and found out that platformstand was making the player not teleport.
Added this and the script works:

local GetPlayer = game.Players:FindFirstChild(part.Name) -- part is equal to workspace.Player1
local prisons = workspace.Prison:GetChildren()
local jailPosition = prisons[math.random(1,#prisons)].CFrame

Using = false		
targetbody.Anchored = false
workspace:FindFirstChild(part.Name).Humanoid.PlatformStand = false

GetPlayer.Character.Humanoid.PlatformStanding:Connect(function(isPlatformStanding)
	if not isPlatformStanding then
		part:SetPrimaryPartCFrame(jailPosition)
	end
end)

Hopefully this can help someone that has the same problem as me. (if they will)