Want to delete a part of a tool on the client. No errors, no nothing. Just does not work and skips right past it. Maybe it’s something with the WaitForChild’s or maybe that I am on the Client, unsure
08:43:26.392 Players.madzxla_tycoon.Backpack.Blue Headphones.theMakeWorkPart.gui.start.TextButton.LocalScript:4: attempt to index nil with 'FindFirstChild' - Client - LocalScript:4
08:43:26.392 Stack Begin - Studio
08:43:26.392 Script 'Players.madzxla_tycoon.Backpack.Blue Headphones.theMakeWorkPart.gui.start.TextButton.LocalScript', Line 4 - Studio - LocalScript:4
08:43:26.393 Stack End - Studio
You have a chain of WaitForChild calls. It’s generally a good practice to avoid too many WaitForChild calls in a row. If any of the calls fail to find the child, the entire chain will fail. Instead, consider breaking it up into separate lines to make debugging easier.
Certain actions, like modifying objects in the Backpack, might be restricted on the client side due to security reasons. You might need to handle the deletion on the server and then communicate the change to the client.
script.Parent.MouseButton1Click:Connect(function()
local tool = game.Players.LocalPlayer.Backpack:FindFirstChild("Blue Headphones")
if tool then
local package = tool:FindFirstChild("package")
if package then
package:Destroy()
print("Package destroyed successfully.")
else
warn("Package not found.")
end
else
warn("Tool not found in Backpack.")
end
script.Parent.Parent.Visible = false
script.Parent.Parent.Parent.main.Visible = true
end)
finally found whats wrong, appereantly, its not there, very weird issue, monitored the backpack and when i equip the tool, the tool gets removed from the backpack, so where is it now? unsure
edit 1: i thought that even if you equip the tool it still stays in the backpack (which it should)
edit 2: turns out, the tool goes to workspace, can i do game.workspace.localplayer or something?? very unsure what to do rn
If the “package” object is being destroyed, it could be causing the tool itself to be removed from the backpack.
Tools are not automatically kept in the backpack when equipped. When you equip a tool, it is moved from the backpack to the character’s character model. It’s not supposed to stay in the backpack.
it seems like you might be misunderstanding how tools work in Roblox. If you want the tool to stay in the backpack even when equipped, you shouldn’t be destroying the “package” object. Instead, you might want to modify your code to achieve the desired behavior.
script.Parent.MouseButton1Click:Connect(function()
local tool = game.Players.LocalPlayer.Backpack:FindFirstChild("Blue Headphones")
if tool then
local package = tool:FindFirstChild("package")
if package then
package:Destroy()
print("Package destroyed successfully.")
else
warn("Package not found.")
end
else
warn("Tool not found in Backpack.")
end
script.Parent.Parent.Visible = false
script.Parent.Parent.Parent.main.Visible = true
end)
basically i have this headphone model, there is packaging/wrap on it and i want it removed when clicking this gui object, its just to remove that packaging part
script.Parent.MouseButton1Click:Connect(function()
local tool = game.Players.LocalPlayer.Backpack:FindFirstChild("Blue Headphones")
if tool then
local package = tool:FindFirstChild("package", true) -- Adding 'true' for case-insensitive search
if package then
package:Destroy()
print("Package destroyed successfully.")
else
warn("Package not found.")
end
else
warn("Tool not found in Backpack.")
end
script.Parent.Parent.Visible = false
script.Parent.Parent.Parent.main.Visible = true
end)
no, the gui appears when the tool is equipped, its not always on the screen, thats the thing, do i go in workspace, get the users username, find the characters model using the players username, and delete it through the character model?
I’m not sure but i think this could be possible like this?:
script.Parent.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
local character = player.Character
if character then
local tool = character:FindFirstChild("Blue Headphones")
if tool then
local package = tool:FindFirstChild("package")
if package then
package:Destroy()
print("Package destroyed successfully.")
else
warn("Package not found.")
end
else
warn("Tool not found in character.")
end
else
warn("Character not found.")
end
script.Parent.Parent.Visible = false
script.Parent.Parent.Parent.main.Visible = true
end)