Reserved Item Script Broken

Hello! Im trying to reserve a item only for game devs, the script doesn’t work at all, and nothing came up in the output as an error nor warning sooooo…
Heres the scripts itself

local players = {"CarlosGamer81239, NubblyFry"}
local tool = game.ServerStorage.DEV_FuseNuke
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		for i = 1, #players do
			if players[i] == plr.Name then
				tool:Clone().Parent = plr:WaitForChild("Backpack")
			end
		end
	end)
end)

This line is a problem. Instead of doing DEV_FuseNuke, do ServerStorage:FindFirstChild(“DEV_FuseNuke”)

1 Like

didn’t work sadly


what is the error on the output?

1 Like

No errors actually come out of the output or console

This is probably due to the player loading before the event is connected.

Put your callback function as some local function, e.g. addPlayer, then also loop over Players:GetPlayers() and call the event for each player.

This is pretty common, and, happens 100% of the time in Studio.

1 Like
ServerStorage:WaitForChild(“DEV_FuseNuke”)

**
Also, you don’t need to check for CharacterAdded, instead you can do this:

game.Players.PlayerAdded:Connect(function(plr
    local char = 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 = "Enter Name"
        end
    end
end)
1 Like

WaitForChild or FindFirstChild, actually it doesn’t matter since it isn’t the issue.

It’s not the issue but using WaitForChild is good practice as sometimes the script loads before the item, and FindFirstChild will just return nil if it does, whereas WaitForChild will wait until it’s loaded.

1 Like

Well yeah, for this script WaitForChild is for sure usefull

Im doing for specific players


callback? also how am I supposed to loopover Players:GetPlayers()

If you’re talking about the players that you’ve already specified in the players table, then that’s exactly what it checks.

1 Like

syntax error

You missed a bracket. Change (plr to (plr)

1 Like

Didn’t work, no errors in the output

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

game.Players.PlayerAdded:Connect(function(plr)
	local char = 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_SwordyMesh"
		end
	end
end)
local players = {"CarlosGamer81239, NubblyFry"}
local tool = game.ServerStorage:FindFirstChild("DEV_FuseNuke")

game.Players.PlayerAdded:Connect(function(plr)
	local char = 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)

Both of the scripts are in the workspace

Your table isn’t separated properly. You need speech marks for each argument, and separate these arguments with a comma. Change your players table to this:

local players = {"CarlosGamer81239", "NubblyFry")
1 Like

local players = {"CarlosGamer81239", "NubblyFry"}
2 Likes