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

Team changing Pad won't work?

Asked by 9 years ago

Hi, I am making a FPS game which has 2 teams. One is Spectators(White colour) and other is In-Game(Bright Blue colour). Whenever I touch the pad, it won't change my team from Spectators to In-Game. The code is written in a Normal Script and it is placed inside workspace, inside a part called TeamChange. Here is the code:

function onTouch(part) 

local human = game.Players.LocalPlayer.Character
if (human ~= nil) and debounce == false then 

game.Players.LocalPlayer.Team = "In-Game"

end 


script.Parent.Touched:connect(onTouch) 

If I did any error in the code, Please let me know in the comments. Thank you for reading/helping!

1 answer

Log in to vote
0
Answered by 9 years ago

You have multiple problems with this script. One being, you need a LocalScript to do this (Ignoring errors that would occur) but I will show you how with a regular script.

First, here's our working code to change the team:

local db = false --Debounce



function onTouch(part) 
    if part.Parent.Humanoid then
        if db == false then db = true
            local Player = game.Players:GetPlayerFromCharacter(part.Parent)--part.Parent IS the character
            Player.TeamColor = BrickColor.new("Black")
            wait(1) 
            db = false
        end 
    end
end
script.Parent.Touched:connect(onTouch) 


Now, you were using LocalScript ONLY things such as LocalPlayer, which would not work in our Script. So instead we need to find out who the person that touched the brick is so we can change their team. To do this we need to use the function :GetPlayerFromCharacter() yet in the parenthesis we must tell whose character touched it. We use 'part.Parent' because the part is what touched it and the Parent is the character.

You will also I changed Teams differently. I'm not sure where you got that way from, but to do this we must change the TeamColor of the player. This TeamColor can be found in the properties of a Player. Changing the TeamColor is just liked changing a BrickColor, you must do `BrickColor.new()' to do this. In my script I made it Black, you must change Black to the color of the team you want.

You are using Debounce incorrectly plus I don't even see the variable of Debounce to be used. First you must set up the variable like I did for db = false and then, later on in the script you need to change it to true so the script will not run it multiple times until db = false. If you have question, comment on this Answer. Accept if this helped!

0
Apparently using Tab made my word in Lua Form. Strange, but I fixed it. alphawolvess 1784 — 9y
0
Thank you for helping! As I new to scripting, A Big thanks to you! :) PlayingOBC 70 — 9y
0
Np, As I have resolution problems, I comment SUPA slow. alphawolvess 1784 — 9y
Ad

Answer this question