#How would I clear the backpack on death and give the player a tool based on the team
1 messages · Page 1 of 1 (latest)
local ServerStorage = game:GetService("ServerStorage")
local TOOL_NAME = "Shield" -- Replace with your tool's name
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
-- Wait for the Backpack to exist
local backpack = player:WaitForChild("Backpack")
local tool = ServerStorage:FindFirstChild(TOOL_NAME)
if tool then
local clonedTool = tool:Clone()
clonedTool.Parent = backpack
else
warn("Tool not found in ServerStorage:", TOOL_NAME)
end
end)
end)
```lua
yeah this was generated by chatgpt
wasnt trying to claim it or anything
sorry if it seemed that way
how did u get s1 tho
Player:WaitForChild("Backpack"):ClearAllChildren()
i think
but im more focused on the team specific gear
i dont think u even got team's code
on what u sent
and u got one tool so idk what u expect
and
does changing team kill u?
yeah i set that up in a different script
but like
i had tried making an if statement
that changes TOOL_NAME based on what team you were on
but it didnt work
show.
local ServerStorage = game:GetService("ServerStorage")
local TOOL_NAME = nil
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
if player.Team == game.Teams["Thunderer"] then
local TOOL_NAME = "Hammer"
elseif player.Team == game.Teams["Super Soldier"] then
local TOOL_NAME = "Shield"
end
-- Wait for the Backpack to exist
local backpack = player:WaitForChild("Backpack")
local tool = ServerStorage:FindFirstChild(TOOL_NAME)
if tool then
local clonedTool = tool:Clone()
clonedTool.Parent = backpack
else
warn("Tool not found in ServerStorage:", TOOL_NAME)
end
end)
end)
i just put the backpack clearing in another script that handles the team changing
which is line 17
local tool = serverstorage?
yeah
the inner local TOOL_NAME declarations shadow the outer variable, TOOL_NAME remains nil when you call FindFirstChild(nil), triggering the “Argument 1 missing or nil” error
u can remove the line 3 local tool
cuz idfk what u need it for
and
the error is cuz toolname is always nil
in your case, neither of the team checks was sucess
i believe
local ServerStorage = game:GetService("ServerStorage")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local TOOL_NAME
if player.Team == game.Teams["Thunderer"] then
TOOL_NAME = "Hammer"
elseif player.Team == game.Teams["Super Soldier"] then
TOOL_NAME = "Shield"
end
print(TOOL_NAME)
-- Wait for the Backpack to exist
local backpack = player:WaitForChild("Backpack")
local tool = ServerStorage:FindFirstChild(TOOL_NAME)
if tool then
local clonedTool = tool:Clone()
clonedTool.Parent = backpack
else
warn("Tool not found in ServerStorage:", TOOL_NAME)
end
end)
end)
I fixed tool name from being nil
but for some reason it doesnt recognize when i switch teams
video
record rq
ignore me messing with the output
your script only ever runs the tool giving logic inside the initial character added handler, so if you switch teams and respawn at the same time then the comparison against player.Team still sees the old or nil value and leaves TOOL_NAME unset 💔
i thought chartacter added runs each time the character respawns
** You are now Level 4! **
it does but CharacterAdded fires before the Team change is applied when a player dies and switches teams simultaneously, so your code reads the old Team value and never sets TOOL_NAME
listen for the player’s team change (player:GetPropertyChangedSignal("Team")) and rerun your tool-assignment code after a team switch
one last thing