If in group teleportation script help

I have a script where people who are in the group 35485008 and have the rank 210-255 should be instantly teleported to 9.838, 22.779, -65.825, yet its not working. help?

local groupId = 35485008
local minRank = 210
local maxRank = 255
local teleportPosition = Vector3.new(9.838, 22.779, -65.825)

local function onPlayerAdded(player)
    print(player.Name .. " joined the game.")
    print(player.Name .. " is in group: " .. tostring(player:IsInGroup(groupId)))
    if player:IsInGroup(groupId) then
        local rank = player:GetRankInGroup(groupId)
        print(player.Name .. "'s rank: " .. rank)
        if rank >= minRank and rank <= maxRank then
            local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
            if humanoidRootPart then
                humanoidRootPart.CFrame = CFrame.new(teleportPosition)
                print(player.Name .. " teleported!")
            else
                print("HumanoidRootPart not found for " .. player.Name)
            end
        end
    end
end

Players.PlayerAdded:Connect(onPlayerAdded)```

I think the problem is the character isn’t loaded in when you teleport the player, so just before you get the players humanoidRootPart, do

local character = player.Character or player.CharacterAdded:Wait()
1 Like

I added local character = player.Character or player.CharacterAdded:Wait() right before local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart") and I’m getting the error Attempt to index nil with 'PlayerAdded' for Players.PlayerAdded:Connect(onPlayerAdded)

you didnt define “Players” (the service)

local Players = game:GetService('Players') --or game.Players, whichever

and if you did and its just not in the post, something is up with the way you defined it

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.