Attempting to create a very simple teleportation script for fun

I’m trying to use the code from this because of the command activating something.
I figured because this activated the message in the chat, I could modify it to also teleport the player, but I can’t seem to get it working.

Here are some images of scrapped code that I swapped out for the original stuff from the linked post:
server.lua : https://gyazo.com/451be108d55c3106918d04f5da3119c0
client.lua : https://gyazo.com/913635f37cfdec95b6d469b871612b79

Also sorry if this isn’t the right place to post this, still trying to figure out the forums!
(Also i know in the client.lua picture the teleport code is a comment, just wanted to try get the text to work)

You do not need a server.lua for this. Only client.lua:

RegisterCommand('hospital', function()
    TriggerEvent('Hospital')
end)
1 Like

What Scott_UK told you is correct, also you are calling the native SetPedCoordsKeepVehicle(...) wrong.

Natives don’t have to be called with TriggerEvent(...).

You just call them how they are.

Example:

Clientsided Script

RegisterCommand('hospital', function(Source, Arguments, RawCommand)
	if #Arguments == 3 then
		if IsPedInAnyVehicle(PlayerPedId(), 0) and (GetPedInVehicleSeat(GetVehiclePedIsIn(PlayerPedId(), 0), -1) == PlayerPedId()) then
			SetPedCoordsKeepVehicle(PlayerPedId(), Arguments[1], Arguments[2], Arguments[3])
		else
			SetEntityCoords(PlayerPedId(), Arguments[1], Arguments[2], Arguments[3])
		end
		TriggerEvent('chatMessage', '', {0, 255, 0}, 'Teleported successfully!')
	else
		TriggerEvent('chatMessage', '', {255, 0, 0}, 'Argument count mismatch! Expected 3, got ' .. #Arguments .. '!')
	end
end)
1 Like

Forgive me for not understanding this, but I don’t understand the arguments within the code, how do those work? I tried entering the xyz’s into them accordingly but that didn’t work, and how would I define the action(‘Hospital’) within Scott’s code? I get the main idea, its just how to fill in the information for the command and how to execute it is what’s tying me up right now.

I dont know lua but c# but from my understanding you have to call the hospital command thru ingame chat like: /hospital

and pass the coordinates as arguments.

I got the /hospital part down, that part is working.

Then what is it you don’t understand

Client.lua:
https://gyazo.com/f7b81ff125018fd3a2099fcbf35257ee

Server.lua
https://gyazo.com/c4f3232049f2fdaf09eb4a1954369318


I’ll type in the game chat /showid and then it proceeds to spew out a long error message in the chat.
give me a moment and ill grab a screenshot