I need help debugging a script that gives tools according to their teamcolor when they join

local players = game:GetService("Players")
local serverStorage = game:GetService("ServerStorage")

local function giveTools(player)
	local backpack = player.Backpack
	local bigblaster = serverStorage["Big Blaster"]
	local gblasters = serverStorage["Gaster Blasters"]
	local bonewalls = serverStorage["Bonewalls"]
	local middlebonewall = serverStorage["Middle Bonewall"]
	if player.TeamColor == BrickColor.new("Navy blue") then
		bigblaster:Clone().Parent = backpack
		gblasters:Clone().Parent  = backpack
		bonewalls:Clone().Parent  = backpack
		middlebonewall:Clone().Parent  = backpack
		print("PLAYER HAS RECEIVED TOOLS.")
	end
end

players.PlayerAdded:Connect(function(plr)
	giveTools(plr)
end)

Here’s my problem: while print("PLAYER HAS RECEIVED TOOLS.") does show, the player when they first load into the game under player.TeamColor == BrickColor.new("Navy blue") does not receive the tools ingame and the output shows absolutely 0 errors. I’ve tried replicatedstorage but it doesn’t work, many other methods also. I’d greatly appreciate receiving help!

Two things to try:

  1. Break up the code into two steps:

    local bigblasterClone = bigblaster:Clone()
    bigblasterClone.Parent = backpack

  2. Or, do not use a variable for backpack

    bigblaster:Clone().Parent = player.Backpack

I have noticed sometimes backpack will not work properly when it is a variable.

I’ve tried both methods and they do not work. print("PLAYER HAS RECEIVED TOOLS.") does appear in the output, but the tools do not appear in the player’s inventory/backpack.

Try like this

players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function()
		giveTools(plr)
	end)
end)

I pasted the code into my script and it definitely worked. Thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.