I’m making a quick game, where you basically throw chairs…
However I’ve run into a problem. My LocalScript detects all the tool equipped and gives them a tag
If the tool has that tag, it will have the function to throw the chair, however, when I unequip the tool, I aded a print() function to see if it’s working, and it’s printing multiple times, and I don’t know the cause?
function setupTool(toolPart)
toolPart.Equipped:Connect(function()
idleAnimationTrack:Play()
end)
toolPart.Unequipped:Connect(function()
idleAnimationTrack:Stop()
return warn("tool unequipped")
end)
mouse.Button1Down:Connect(function()
if toolPart.Parent == character then
if thrown == false then
thrown = true
throwbeginAnimationTrack:Play()
end
end
end)
mouse.Button1Up:Connect(function()
if toolPart.Parent == character then
if thrown == true then
if throwAnimationTrack.IsPlaying == false then
throwAnimationTrack:Play()
throwbeginAnimationTrack:Stop()
end
end
end
end)
throwAnimationTrack:GetMarkerReachedSignal("Throw"):Connect(function()
thrown = false
throwEvent:FireServer(mouse.Hit.Position, toolPart.Handle:FindFirstChild("FirePoint"),toolPart.Damage.Value, finalSpeed, toolPart.Handle, toolPart.Handle.Throw)
throwAnimationTrack:Stop()
end)
end
character.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
child:AddTag("EquippedTool")
end
end)
character.ChildRemoved:Connect(function(tool)
if tool:IsA("Tool") then
tool:RemoveTag("EquippedTool")
end
end)
collectionService:GetInstanceAddedSignal("EquippedTool"):Connect(setupTool)
From what I understood
is this the part that throws the Chair?
Well you can do Debounce
local Debounce = false
mouse.Button1Down:Connect(function()
if toolPart.Parent == character then
if thrown == false and Debounce == false then
Debounce = true
thrown = true
throwbeginAnimationTrack:Play()
task.wait(1) --Cooldown here
Debounce = false
else
warn("On Cooldown")
end
end
end)
local connectedTools = {}
function setupTool(toolPart)
if connectedTools[toolPart] then
return -- Already connected for this tool
end
toolPart.Equipped:Connect(function()
idleAnimationTrack:Play()
})
toolPart.Unequipped:Connect(function()
idleAnimationTrack:Stop()
return warn("tool unequipped")
end)
mouse.Button1Down:Connect(function()
if toolPart.Parent == character then
if thrown == false then
thrown = true
throwbeginAnimationTrack:Play()
end
end
})
mouse.Button1Up:Connect(function()
if toolPart.Parent == character then
if thrown == true then
if throwAnimationTrack.IsPlaying == false then
throwAnimationTrack:Play()
throwbeginAnimationTrack:Stop()
end
end
end
})
throwAnimationTrack:GetMarkerReachedSignal("Throw"):Connect(function()
thrown = false
throwEvent:FireServer(mouse.Hit.Position, toolPart.Handle:FindFirstChild("FirePoint"),toolPart.Damage.Value, finalSpeed, toolPart.Handle, toolPart.Handle.Throw)
throwAnimationTrack:Stop()
end)
connectedTools[toolPart] = true
end
character.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
child:AddTag("EquippedTool")
setupTool(child)
end
end)
character.ChildRemoved:Connect(function(tool)
if tool:IsA("Tool") then
tool:RemoveTag("EquippedTool")
connectedTools[tool] = nil
end
end)
collectionService:GetInstanceAddedSignal("EquippedTool"):Connect(function(tool)
setupTool(tool)
end)
hardly read through your script, but it seems like the function is only firing if the tool is equipped…maybe modify it to fire when it is both equipped and unequipped? otherwise the unequipped function will never fire…or have it run outside the setupTool function?
nope, should i make like a custom backpack? since I have another game with a custom backpack system and i figured it would work better if i did this, or should i do separate scripts for each tool?
I think it’s because throwing the chair, which I’m guessing removes from your inventory, isn’t getting its tag removed. I know barely anything about tags, but my guess has to do with that area. It’s possible that the setupTool function gets fired multiple times, so that’s why the unequip is printing multiple times.