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

[SOLVED] Roblox "Clone" function seems to not work, is it glitched?

Asked by 5 years ago
Edited 3 years ago

Explanation: So I'm trying to write a simple code but the code doesn't seem to work. So I have 3 teams in the game named "Hospital Staff", "Patient" and "Guest". The player will be in team "Hospital Staff" only if they are in the group and have certain rank. They will be "Patient" if they are in the group and are only a member of it. Player will be in team "Guest" if they are not in the group.

Problem: I tried to clone a tool named "KeyCard" from ServerStorage to Player's Backpack but it seemed to be glitched. I tried to print "Cloned" if the tool is cloned in the Backpack and "Not Cloned" if it is not. What surprises me is that when I joined the game, the script printed "Cloned" but I did not have any tool in my Backpack. Then I tried to check my Backpack in explorer but could not find as well.

Here is my ServerScript located in ServerScriptService named "TeamAssignServer" :

01local Players = game:GetService("Players")
02local Teams = game:GetService("Teams");
03 
04local Hospital_Staff = Teams["Hospital Staff"]
05local Patient = Teams.Patient
06local Guest = Teams.Guest
07 
08Players.PlayerAdded:Connect(function(Player)
09    if(Player:IsInGroup(5786709)) then
10        print("Player Is In Group: Robloxia City Hospital")
11        print("Player's Rank Is: "..Player:GetRankInGroup(5786709))
12        local Rank  = Player:GetRankInGroup(5786709)
13        if Rank > 1 then
14            Player.TeamColor =  Hospital_Staff.TeamColor
15            print("Team Changed, Player's Team Is Hospital Staff")
View all 32 lines...

1 answer

Log in to vote
2
Answered by
Nanomatics 1160 Moderation Voter
5 years ago

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.

01local Players = game:GetService("Players")
02local Teams = game:GetService("Teams");
03 
04local Hospital_Staff = Teams["Hospital Staff"]
05local Patient = Teams.Patient
06local Guest = Teams.Guest
07 
08Players.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)
14        if Rank > 1 then
15            Player.TeamColor =  Hospital_Staff.TeamColor
View all 33 lines...

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

0
Thanks. I actually tried that but i put repeat wait() until Player instead of Player.Character. Thanks for the fix too tho, didn't notice it guest_20I8 266 — 5y
Ad

Answer this question