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.