Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Is it possible to make random destination teleporters?

Asked by 6 years ago
Edited 6 years ago

Is it possible to make a teleporter that teleports you to one block or another randomly? I tried but it isn't working. I am also trying to make it click-activated. This is my (normal) script inside the teleporter

function Click(Player, teleport)
    if Player.Parent:FindFirstChild("HumanoidRootPart") then
        local human = Player.Parent.HumanoidRootPart
        teleport = math.random(1,2)
        if teleport == 1 then
            human.Position = Vector3.new(-875.194, -71.321, -1068.287) 
        end  -- Destination A
        if teleport == 2 then
            human.Position = Vector3.new(-875.194, -71.321, -931.699) 
        end   -- Destination B
    end
end

script.Parent.ClickDetector.MouseClick:Connect(Click)
1
well, because the humanoid Root part is the in character, not in the players service nor the player object theking48989987 2147 — 6y
0
MouseClick only gives you one argument - Click has two. Get rid of the "teleport" argument in Click. fredfishy 833 — 6y
0
also, you could have a corresponding array of locations that can be indexed , this would excessive use of if statements theking48989987 2147 — 6y
0
Could you please accept my answer if it worked? User#24403 69 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

The MouseClick event passes the player who clicked, not what touched it. You seem to be getting it confused with the Touched event of parts. Additionally, you should teleport with CFrame, and not Vector3. By changing the position you're literally moving the HumanoidRootPart to the coordinates and not the entire character. Using CFrame, you move the entire character.

local function Click(Player)
    local teleport = math.random(1,2)

    if teleport == 1 then
        Player.Character:SetPrimaryPartCFrame(CFrame.new(-875.194, -71.321, -1068.287))
    else:
        Player.Character:SetPrimaryPartCFrame(CFrame.new(-875.194, -71.321, -931.699))
    end
end

script.Parent.ClickDetector.MouseClick:Connect(Click)
0
Thanks for the help it worked! Boi52893642864912 69 — 6y
Ad

Answer this question