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

My Playertool script breaks when adding a limit to it?

So this script gives the players in the list the tool of " local gear "

But from the moment I try to ad the part where if the player is in a specific team the player won't get the tool and in another specific team they will get the tool it breaks..

local players = {"player", "player", "player"}          --I know I have to change it into the real names
local gear = game.ServerStorage.ReverseDual

game.players.playerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(chr)
        for i = 1, #players do
            if players[i] == plr.Name and players.Team == "The Jedi Order" or "Raiders" then
                gear:Clone().Parent = plr:WaitForChild("Backpack") == true


game.players.playerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(chr)
        for i = 1, #players do
if players[i] == plr.Name and players.Team == "Shadows" or "Temple Guard" then
	gear:Clone().Parent = plr:WaitForChild("Backpack") == false
	
            end
        end
    end)
end)

Thanks in advance

1 answer

✓ Accepted answer

Your code is really messed up. You connect to PlayerAdded again in CharacterAdded which is completly pointless.

Try doing something like this:

local plrs = {
	["Player1"] = true,
	["Player2"] = true,
}

local gear = game:GetService("ServerStorage").ReverseDual

game:GetService("Players").PlayerAdded:Connect(function(plr)
	if not plrs[plr.Name] then
		return --exit the function if the player isn't in the plrs table
	end

	plr.CharacterAdded:Connect(function()
		if plr.Team.Name == "The Jedi Order" or plr.Team.Name == "Raiders" then --check if they are in the team The Jedi Order or Raiders, and if they are, clone the gear to their backpack
			gear:Clone().Parent = plr:WaitForChild("Backpack")
		end
	end)
end)

1 comment

0

Thanks! also thanks for explaining it I haven't worked with giving players specific gears yet only with team gear etc.

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