Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is it possible to make random destination teleporters?

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)

4 comments

1

well, because the humanoid Root part is the in character, not in the players service nor the player object

0

MouseClick only gives you one argument - Click has two. Get rid of the "teleport" argument in Click.

0

also, you could have a corresponding array of locations that can be indexed , this would excessive use of if statements

0

Could you please accept my answer if it worked?

1 answer

✓ Accepted answer

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)

1 comment

0

Thanks for the help it worked!

This discussion is preserved as it was. New answers, comments, and votes are closed.