Teleport error (Basic Scripting)

Hello! This is my first ever post so I am sorry if it is not in the right category!
I own a type of „Find the Button‟ game and I have been having a pretty much big error with the button. When a player finds a button and presses it, the player should be teleported to the next room, however my button teleports EVERYONE in the server to the next room from that level!

Here is the script:

function onClicked()

local p = game.Players:GetChildren()

for i = 1, #p do





I tryed everything to fix it but since I am not a good scripter, I am not sure on how to make it so only the player touching the button gets teleported!
Thank you in advance!

Welcome! This is the correct Category.

The Reason its teleporting everyone is because you are indexing in the for loop to get all the Players

Instead, Try getting the Player with MouseClick

script.Parent.ClickDetector.MouseClick:connect(function(Player) -- Player is Always the first Argument in this Connection

so i should replace all the script with this one? (Im so bad at scripting)

I mean, you can copy it, I provided it to you since you were asking for help :slight_smile:

so again, i delete the old script and i just copy this new one right? :slight_smile:

Just Modify it, don’t completely delete it because it might affect your Code (if you have more code than this)

However if thats all you have, feel free!

Sadly it still teleports everyone in the server :frowning:

Can you Please show the Script?

This was the old script and than i deleted it all and replaced it with yours. There is nothing more in the script than i quoted!

This should be all you need to do:

function onClicked(Plr)


This is just the other way of doing it

1 Like
function onClicked(p)

    local c = p.Character

    if c then
       local hrp = c:FindFirstChild("HumanoidRootPart")

       if hrp then
          hrp.Position = NextButtonPosition -- CHANGE THIS




now you cant even touch the button :frowning:

what do you mean?

It should teleport the Player

Although this is an alternate way of doing this, it can be a bit weird as it could offset the HumanoidRootPart (Take this with a grain of salt), Instead use MoveTo or PivotTo

let me try once more and I will see if it works

Oh, thanks, I will start using MoveTo and PivotTo.

It works now!! Thank you so much!!!

1 Like

Thank you for all the help! I will now apply the script!

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