Teleport to player not working

Hello, this is my tp function:

RegisterCommand('tp', function(args, source)
	local localPed = GetPlayerPed(-1)
	local destPed = GetPlayerPed(args[1])
	local coords = GetEntityCoords(destPed)
	SetEntityCoords = (localPed, coords.x, coords.y, coords.z, true, false, false, true)
end, false)

but when i type /tp [name of player] nothing happen
i’m new so please don’t flame me

1 Like

You don’t use an = for a native. It’s:

SetEntityCoords(localPed, coords.x, coords.y, coords.z, true, false, false, true)
1 Like

I’ve tried without ‘=’ but nothing has changed

I’ve forgot to say that the script is client side

RegisterCommand('tp', function(source, args, raw)
	local localPed = GetPlayerPed(-1)
	local destPed = GetPlayerPed(args[1])
	local coords = GetEntityCoords(destPed)
	SetEntityCoords = (localPed, coords.x, coords.y, coords.z, true, false, false, true)
end, false)

Are you trying to TP to a player by doing /tp [playerid]???

Like he said, he is looking for a command to /tp [player name] and not /tp [player id]
:face_with_raised_eyebrow:

you will need to loop through the indices and find the right player by matching the name, you can do it easily, but don’t ask me to spoonfeed you, this is all the advices i’ll give you.

I didn’t read the top post I was just looking at comments and missed what he said above so maybe not be rude huh? Also why are you saying something when you aren’t here to help him in the first place.

@Danilo_Maglia have not tested this but maybe try this?

RegisterCommand("tp", function(source, args, raw)
	local name = table.concat(args)
	local player = FindPlayerWithName(name)
	if player ~= nil then
		TeleportToPlayer(player)
	end
end, false)

function TeleportToPlayer(player)
	local lPed = GetPlayerPed(PlayerId())
	local oPed = GetPlayerPed(player)
	local oPedPos = GetEntityCoords(oPed, false)
	SetEntityCoords(lPed, oPedPos.x, oPedPos.y, oPedPos.x, 0.0, 0.0, 0.0, false)
end

function FindPlayerWithName(string)
	local players = GetPlayers()
	for a = 1, #players do
		if GetPlayerName(a) == string then
			return a
		end
	end
	return nil
end

should i put it in client or server?

anyway the script doesn’t work, maybe i did something wrong but i tried it server-side then client-side but it doesn’t work

Just because, as you said, you didnt even took the time to read the post. Anyway was just to precise. You were asking

Doesnt matter what I took the time to do. I am here helping and planned to help when I posted my first comment. Its people like you that make the community not wanna help at all over a small mistake just because the way you put it makes you guys sound cocky and disturbing. You warent here helping before I commented and you arent helping after you commented so what was the point. He could have clarified my question I dont believe he needed outside help.

1 Like

Client sided script and I need more details then “It doesnt work”. Does the script have errors? How did you put it on your server? Did you load the script in your resource.lua? Are you starting your resource in the server.cfg?

As before when i type /TP [name of player] nothing happens with no error i put it in cfx-server-data/resources/[local]/ITProud
In My cfg i start ITProud

Ok. I will have to test the script then and see if I can get it working.

RegisterCommand("tp", function(source, args, raw)
	local name = table.concat(args)
	local player = FindPlayerWithName(name)
	if player ~= nil then
		TeleportToPlayer(player)
	end
end, false)

function TeleportToPlayer(player)
	local lPed = GetPlayerPed(PlayerId())
	local oPed = GetPlayerPed(player)
	local oPedPos = GetEntityCoords(oPed, false)
	SetEntityCoords(lPed, oPedPos.x, oPedPos.y, oPedPos.z + 1.0, 0.0, 0.0, 0.0, false)
end

function FindPlayerWithName(string)
	for a = 0, 64 do
		if GetPlayerName(a) == string then
			return a
		end
	end
	return nil
end

This code works on my dev server. Make sure you get their name exactly right.
There was an error in the console so I just fixed that error.

Hello how can i make tp an id at a precise coordinate please?

can you add like a permission function to this like when someone wants to tp to another player it ask for permission instead of tping to them?