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

How to make a script that only lets certain players teleport to a room?

Asked by
D4_rrk 89
3 years ago

I want to make a script that only lets people that don't have a bool value (called "IsHunter" which is inside their Character) teleport inside the room, I've tried using If statements but that just lets people with the bool value teleport inside, same for people that don't have the bool value.

1 answer

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

Let's think about how we could do this logically. What we need to do is go through all the players, and check if they have an IsHunter value inside of their character.

To loop through all the players, you can use a for loop, like this:

local players = game:GetService('Players')
for _,v in ipairs(players:GetPlayers()) do
    print(v.Name)
end

The code above will print all the player's names. Cool! We now know how to loop through all players. Now, to check if they have an IsHunter object in their Character, we can simply do the following:

local players = game:GetService('Players')
for _,v in ipairs(players:GetPlayers()) do
    if v.Character:FindFirstChild('IsHunter') then
        v.Character:SetPrimaryPartCFrame(yourCframeHere)
    end
end

Now all you need to do is replace yourCframeHere with the destination and it should work.

Hope this helped

0
Thanks for the help! D4_rrk 89 — 3y
Ad

Answer this question