What I’m trying to accomplish is if someone’s already holding a box, they can’t pick up another box. The problem is that when it checks to see if the player already has a box, if the player has a box, the box on the floor gets put in the player’s character, but the existing box gets deleted. The script is within the handle of the box. Anyone able to help?
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if not hit.Parent:FindFirstChild("Box") then
script.Parent.Parent.Parent = hit.Parent
end
end
end)
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if not hit.Parent:FindFirstChild("Box") then
script.Parent.Parent.Parent = hit.Parent
script:Destroy() -- Added line
end
end
end)
My guess is that since it’s a Tool object, you aren’t assigning it to the Player’s Backpack but rather to the Player’s Character Model instead which wouldn’t work that way
Instead, maybe try this?
script.Parent.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player and not hit.Parent:FindFirstChild("Box") then
script.Parent.Parent.Parent = Player.Backpack
end
end
end)
The default behaviour of tools is to be equipped when stepped over, I thnik what you could do instead is to the put the tool to clone somewhere such as ServerStorage, and instead of putting tools down, put the box models and make it so when a part of the model is touched and you don’t have a box, it clones the tool and equips it via Humanoid:EquipTool() and destroy the box model, otherwise do nothing
script.Parent.Touched:Connect(function(hit)
print("touched")
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player and not hit.Parent:FindFirstChild("Box") then
print("staement true")
script.Parent.Parent = Player.Backpack
end
end)
--tell us what it prints