#teleport not working

9 messages · Page 1 of 1 (latest)

tardy dragon
#

what's wrong with this script?

local teleportParts = {}
local player = game.Players.LocalPlayer

local function teleportToRandomPart()
    if #teleportParts > 0 then
        local randomIndex = math.random(1, #teleportParts)
        local randomPart = teleportParts[randomIndex]

        player.Character:SetPrimaryPartCFrame(randomPart.CFrame)
    end
end

local function onTouch(hit)
    local character = hit.Parent
    if character:IsA("Model") and character:FindFirstChild("Humanoid") then
        if table.find(teleportParts, hit) then
            teleportToRandomPart()
        end
    end
end

teleportParts[1] = workspace.Part1
teleportParts[2] = workspace.Part2
teleportParts[3] = workspace.Part3
teleportParts[4] = workspace.Part4

for _, part in ipairs(teleportParts) do
    part.Touched:Connect(onTouch)
end

I'm meant to touch a part and it's meant to teleport me to 1 of 4 random other parts but nothing's happening.

zinc crystal
#

why are u doing table.find(teleportParts, hit)?

#

also SetPrimaryPartCFrame is deprecated

#

use PivotTo(CFrame)

#
local function onTouch(hit)
    local touchedPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
    if touchedPlayer == player then
        teleportToRandomPart()
    end
end
scenic elbow
gusty marten
zinc crystal
zinc crystal