There is actually nothing wrong with your script, it's just you are doing everything very quickly.
That being said the player didn't fully load
in when you cloned
the tool
into their backpack
, that's why you didn't see it. So I added a line that waits until the character
loads in.
01 | local Players = game:GetService( "Players" ) |
02 | local Teams = game:GetService( "Teams" ); |
04 | local Hospital_Staff = Teams [ "Hospital Staff" ] |
05 | local Patient = Teams.Patient |
06 | local Guest = Teams.Guest |
08 | Players.PlayerAdded:Connect( function (Player) |
09 | repeat wait() until Player.Character |
10 | if (Player:IsInGroup( 3426179 )) then |
11 | print ( "Player Is In Group: Robloxia City Hospital" ) |
12 | print ( "Player's Rank Is: " ..Player:GetRankInGroup( 3426179 )) |
13 | local Rank = Player:GetRankInGroup( 3426179 ) |
15 | Player.TeamColor = Hospital_Staff.TeamColor |
16 | print ( "Team Changed, Player's Team Is Hospital Staff" ) |
17 | local KeyCardClone = game.ServerStorage.KeyCard:Clone() |
18 | KeyCardClone.Parent = Player.Backpack |
19 | if Player.Backpack:FindFirstChild( "KeyCard" ) then |
20 | print ( "KeyCard Cloned" ) |
22 | print ( "KeyCard Not Cloned!" ) |
24 | elseif (Rank = = 1 ) then |
25 | Player.TeamColor = Patient.TeamColor |
26 | print ( "Team Changed, Player's Team Is Patient" ) |
29 | Player.TeamColor = Guest.TeamColor |
30 | print ( "Player Is Not In Group: Robloxia City Hospital!" ) |
31 | print ( "Team Changed, Player's Team Is Guest" ) |
I also fixed where you assigned the player's team to Guest
and Patient
, you forgot the .TeamColor
Hope I helped, please let me know if you have any questions