Developer Path45 minutesBeginner
First Script Walkthrough
Build a complete, useful FiveM script from scratch: a teleport waypoint command. Every line explained.
Prerequisites
- ✓Lua Starter Template completed (or understood)
- ✓A running FiveM server with your test resource
- ✓VS Code with Lua extension
1.What We're Building
A /tp command that teleports you to your map waypoint. Simple, useful, and teaches core FiveM concepts: commands, natives, player ped, coordinates, and validation.
Expected Result
Player sets a waypoint on the map, types /tp, and instantly teleports to that location.
2.Step 1: Create the Resource
Terminal
mkdir -p resources/[local]/tp-waypoint/client
mkdir -p resources/[local]/tp-waypoint/sharedfxmanifest.lua
fx_version 'cerulean'
game 'gta5'
name 'tp-waypoint'
description 'Teleport to map waypoint'
author 'Your Name'
version '1.0.0'
shared_scripts { 'shared/*.lua' }
client_scripts { 'client/*.lua' }3.Step 2: Configuration
shared/config.lua
Config = {}
Config.Command = 'tp'
Config.RequirePermission = true -- Require admin ACE?
Config.AcePermission = 'command.tp'
Config.CooldownSeconds = 5
Config.FadeEffect = true -- Fade screen during teleport?4.Step 3: Client Script
client/main.lua
local lastTeleport = 0
RegisterCommand(Config.Command, function()
-- Cooldown check
local now = GetGameTimer()
if now - lastTeleport < Config.CooldownSeconds * 1000 then
local remaining = math.ceil((Config.CooldownSeconds * 1000 - (now - lastTeleport)) / 1000)
ShowNotification(('Wait %d seconds'):format(remaining))
return
end
-- Check if waypoint is set
if not IsWaypointActive() then
ShowNotification('Set a waypoint on the map first!')
return
end
-- Get waypoint coordinates
local waypointBlip = GetFirstBlipInfoId(8) -- 8 = waypoint blip
local coords = GetBlipInfoIdCoord(waypointBlip)
-- Get ground Z coordinate (height)
local ped = PlayerPedId()
local found, groundZ = false, coords.z
-- Try to find ground level
for z = 1000.0, 0.0, -25.0 do
SetEntityCoordsNoOffset(ped, coords.x, coords.y, z, false, false, false)
Wait(50)
found, groundZ = GetGroundZFor_3dCoord(coords.x, coords.y, z, false)
if found then break end
end
-- Fade effect
if Config.FadeEffect then
DoScreenFadeOut(250)
Wait(300)
end
-- Teleport
SetEntityCoords(ped, coords.x, coords.y, groundZ + 1.0, false, false, false, true)
lastTeleport = now
if Config.FadeEffect then
Wait(200)
DoScreenFadeIn(250)
end
ShowNotification('Teleported to waypoint!')
end, false)
-- Helper function for notifications
function ShowNotification(text)
SetNotificationTextEntry('STRING')
AddTextComponentString(text)
DrawNotification(false, false)
end
print('[tp-waypoint] Loaded successfully')5.Step 4: Test It
- Add 'ensure tp-waypoint' to your server.cfg
- Restart the server or type 'refresh' then 'restart tp-waypoint' in console
- In-game: open map, set a waypoint, type /tp
- You should teleport to the waypoint location with a fade effect
- Try without a waypoint set — should show error message
- Try spamming the command — cooldown should prevent rapid use
Expected Result
Command works, cooldown works, error handling works, no errors in F8 console.
6.Step 5: Improve It
Now that the basic script works, here are improvements to practice more FiveM concepts:
- Add ACE permission check (if Config.RequirePermission, check IsPlayerAceAllowed)
- Add a loading spinner NUI while finding ground Z
- Add server-side logging (who teleported where)
- Add a /tpc command that teleports to coordinates instead of waypoint
- Package it for release: add README, LICENSE, screenshots
First Script Complete
You built a working FiveM script with commands, natives, validation, cooldowns, and visual effects. You now understand the core patterns used in every FiveM resource.