Admin Weapons Script Isn't working

Hello! So I’m trying to make it so admins have weapons, but whenever I try to make it so that whenever the admins or devs respawn, and when they join the game that they get the weapons, but that doesnt work with my script. Here’s the error,

the script

local players = {"CarlosGamer81239", "NubblyFry"}
local tool = game.ServerStorage:FindFirstChild("DEV_FuseNuke")

game.Player.PlayerAdded:Connect(function(plr)
	local char = plr.CharacterAdded while true do
	local backpack = plr:WaitForChild("Backpack")

	for _,v in pairs(players) do
		if plr.Name == v then
			local newTool = tool:Clone()
			newTool.Parent = backpack
			newTool.Name = "DEV_FuseNuke"
		end
	end
end
1 Like

You only need a parenthesis in the last end: end)

and this line why?
You can use StarterGear to not add the tool every time the Character is loaded, this works best:

local players = {"CarlosGamer81239", "NubblyFry"}
local tool = game.ServerStorage:FindFirstChild("DEV_FuseNuke")

game.Player.PlayerAdded:Connect(function(plr)
	if table.find(players,plr.Name) then
		local newTool = tool:Clone()
		newTool.Parent = plr.StarterGear
		newTool.Name = "DEV_FuseNuke"
	end
end)
2 Likes

Syntax error, just create a CharacterAdded event instead

local players = {"CarlosGamer81239", "NubblyFry"}
local tool = game.ServerStorage:FindFirstChild("DEV_FuseNuke")

game.Players.PlayerAdded:Connect(function(plr)
	local backpack = plr:WaitForChild("Backpack")

    plr.CharacterAdded:Connect(function(char)

	    for _,v in pairs(players) do
		    if table.find(players, v.Name) then
			    local newTool = tool:Clone()
			    newTool.Parent = backpack
			    newTool.Name = "DEV_FuseNuke"
		    end
        end

	end)
end)
2 Likes

You should put while true do after the char line.

1 Like
  1. Why do you have a while true do loop inside of the line which is indexing char…?
  2. The end on the last line needs to have a closed bracket.
1 Like
local players = {"CarlosGamer81239", "NubblyFry"}
local tool = game.ServerStorage:WaitForChild("DEV_FuseNuke")

game.Player.PlayerAdded:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	local backpack = plr:WaitForChild("Backpack")

	if plr and plr.Name = players[1] or players[2] then
       local newTool = tool:Clone()
       newTool.Parent = backpack
   end
end)

Fixed up code.

1 Like

There’s a lot of syntax errors you have oof, try it again I edited it

1 Like

just a few syntax errors.

local players = {"CarlosGamer81239", "NubblyFry"}
local tool = game.ServerStorage:FindFirstChild("DEV_FuseNuke")

game.Players.PlayerAdded:Connect(function(plr) -- needed an extra 's' at the end of players
    plr.CharacterAdded:Connect(function(char)
	   local backpack = plr:WaitForChild("Backpack")

	   for _,v in pairs(players) do
		   if plr.Name == v then
			  local newTool = tool:Clone()
			  newTool.Parent = backpack
			  newTool.Name = "DEV_FuseNuke"
		   end
	   end
    end)
end) -- needed an )
2 Likes

local players = {"CarlosGamer81239", "NubblyFry"}
local tool = game.ServerStorage:FindFirstChild("DEV_FuseNuke")

game.Players.PlayerAdded:Connect(function(plr) 
    local char = plr.Character or plr.CharacterAdded:Wait()
	   local backpack = plr:WaitForChild("Backpack")

	   for _,v in pairs(players) do
		   if plr.Name == v then
			  local newTool = tool:Clone()
			  newTool.Parent = backpack
			  newTool.Name = "DEV_FuseNuke"
		   end
	   end
end)

Works perfectly, Thanks!


1 Like