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

How do you get a script to work on everyone who joins a game?

Asked by 5 years ago
Edited 5 years ago

So this script seems to only work for the first person to join a game.

For example:

If I joined the game first it'll give me the group uniform but anyone else who joins the game after me won't get their group uniform.

But I got a friend to join first and it gave him his group uniform but when I joined after him it didn't give me my group uniform this time.

So I am just wondering how I can get the script to work for every player that joins the game every time.

And I've tried loads of different things to try and make it work but nothing, I'm not the strongest with lua :/

local GroupId = 4217419

game.Players.PlayerAdded:Connect(function(plr)
if plr:GetRankInGroup(GroupId) == 246 then
game.Workspace[plr.Name]:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://2165624791"
game.Workspace[plr.Name]:WaitForChild("Pants").PantsTemplate = "rbxassetid://2165669286"
end

if plr:GetRankInGroup(GroupId) == 247 then
game.Workspace[plr.Name]:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://2165624791"
game.Workspace[plr.Name]:WaitForChild("Pants").PantsTemplate = "rbxassetid://2165669286"
end

if plr:GetRankInGroup(GroupId) == 248 then
game.Workspace[plr.Name]:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://2165624316"
game.Workspace[plr.Name]:WaitForChild("Pants").PantsTemplate = "rbxassetid://2165669286"
end

if plr:GetRankInGroup(GroupId) == 249 then
game.Workspace[plr.Name]:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://2165624316"
game.Workspace[plr.Name]:WaitForChild("Pants").PantsTemplate = "rbxassetid://2165669286"
end

if plr:GetRankInGroup(GroupId) == 250 then
game.Workspace[plr.Name]:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://2165632105"
game.Workspace[plr.Name]:WaitForChild("Pants").PantsTemplate = "rbxassetid://2165673300"
end

if plr:GetRankInGroup(GroupId) >= 251 then
game.Workspace[plr.Name]:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://2165667431"
game.Workspace[plr.Name]:WaitForChild("Pants").PantsTemplate = "rbxassetid://2165669286"
        end
end)

1 answer

Log in to vote
0
Answered by
zBoltZz 10
5 years ago
Edited 5 years ago

Try using elseif instead of a bunch of ifs and ends, the code should look something like this:


local GroupId = 4217419 game.Players.PlayerAdded:Connect(function(plr) if plr:GetRankInGroup(GroupId) == 246 then game.Workspace[plr.Name]:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://2165624791" game.Workspace[plr.Name]:WaitForChild("Pants").PantsTemplate = "rbxassetid://2165669286" elseif plr:GetRankInGroup(GroupId) == 247 then game.Workspace[plr.Name]:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://2165624791" game.Workspace[plr.Name]:WaitForChild("Pants").PantsTemplate = "rbxassetid://2165669286" elseif plr:GetRankInGroup(GroupId) == 248 then game.Workspace[plr.Name]:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://2165624316" game.Workspace[plr.Name]:WaitForChild("Pants").PantsTemplate = "rbxassetid://2165669286" elseif plr:GetRankInGroup(GroupId) == 249 then game.Workspace[plr.Name]:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://2165624316" game.Workspace[plr.Name]:WaitForChild("Pants").PantsTemplate = "rbxassetid://2165669286" elseif plr:GetRankInGroup(GroupId) == 250 then game.Workspace[plr.Name]:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://2165632105" game.Workspace[plr.Name]:WaitForChild("Pants").PantsTemplate = "rbxassetid://2165673300" elseif plr:GetRankInGroup(GroupId) >= 251 then game.Workspace[plr.Name]:WaitForChild("Shirt").ShirtTemplate = "rbxassetid://2165667431" game.Workspace[plr.Name]:WaitForChild("Pants").PantsTemplate = "rbxassetid://2165669286" end end)
Ad

Answer this question