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

How can I make a script that separates everyone that don't have a Bool Value?

Asked by
D4_rrk 89
3 years ago

How can I make a script that looks through every player's Character and if the script finds a Bool Value inside the player's Character Model then they get teleported to a destination and if the script doesn't find any Bool Value in everyone else, then the ones that didn't have a Bool Value get teleported to a different destination.

1 answer

Log in to vote
0
Answered by 3 years ago

Ok, I am a bit rusty with this kind of stuff but you basically need to loop through every player and retrieve their character from the player and see if there is a bool value inside. After that just set the primary part cframe and it should work :D

for i,player in pairs(game.Players:GetPlayers()) do
    print("player")
    local character = player.Character
    if character then
        print("character")
        local playerbool = character:FindFirstChild("PlayerBoolValue")
        if playerbool then
            if playerbool.ClassName == "BoolValue" then
                print("boolfound")
                character:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0,0,0)))
                -- Vector3.new(0,0,0) should be the position you want the character to be or a part.Position
            end
        end
    end
end
0
Btw, put the code in a script in the workspace if you want and see what will happen if you put wait(15) at the top of the code. Futuristic_Paladin 19 — 3y
0
I got an error when the script got to the for loop, Workspace.GameController:50: attempt to call a nil value D4_rrk 89 — 3y
0
Turns out I just had to remove :GetPlayers() and it worked, thanks for the help! D4_rrk 89 — 3y
0
Yay :D Futuristic_Paladin 19 — 3y
0
Using ClassName is bad practice, use IsA() instead as it supports inheritance. Also, isn't any object called PlayerBoolValue going to be a bool value? You don't really need to check. brokenVectors 525 — 3y
Ad

Answer this question