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

Any way to simplify this or make it work?

So I added on to this script from another question and it doesn't work and it's kinda long. I wanted to see if I could make it shorter. Essentailly the admins get put on the lapiz team and they spawn in a certain position. However it doesn't work and it a bit long. Any help or improvements that will make it work?


admins = {
["conman0552"] = true;
}


game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(char)
        if admins[player.Name] then
            print(player.Name.." is an admin of this game")
            char:MoveTo(Vector3.new(91.51, 119.988, -8.701))
            player.TeamColor = BrickColor.new("Lapis") -- Look at the example of this below the script.
        end
    end)
end)




Yes I have tried Color3 and I have used the number 307 in this. On another script this same team changing formate works just fine.

1 comment

3

It's basically as short as you can make it while keeping it neat and clean

2 answers

✓ Accepted answer

MoveTo() must have a Vector3 as the argument.

char:MoveTo(Vector3.new(91.51, 119.988, -8.701))

The second problem I found was a bit weirder, basically CharacterAdded is fired super soon after respawn, so your teleport code runs but then your char is teleported (by default) to whatever spawn they were at before. This can be fixed by adding a tiny wait at the beginning of the event.

player.CharacterAdded:connect(function(char)
	wait(0.1)

It would also be a good idea to just check if the player is an admin once, when they join, instead of each time they respawn. This also makes it so that less events are connected, because you are only listening for when the admins respawn, again increasing efficiency.

admins = {
["conman0552"] = true;
}


game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(char)
        if admins[player.Name] then
            print(player.Name.." is an admin of this game")
            char:WaitForChild("Humanoid").MaxHealth = 500
            char:WaitForChild("Humanoid").Health = 500
            char.Torso.Position.CFrame = CFrame.new(91.51, 119.988, -8.701)
            player.TeamColor = BrickColor.new("Lapis") --In your case
        end 
    end)
end)

What I believe you did wrong is that you used an invalid color in your code, From the number is literally a number, use the color's name instead.

1 comment

0

It did not work with the string name but it worked with 307

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