What do you want to achieve? Keep it simple and clear!
I want to make it so that different animations play when you attack with different weapons/tools.
What is the issue? Include screenshots / videos if possible!
I duplicated my punch script I already have (by Majestic Dev on YT). I put different animations and I’m trying to make it so the script is only enabled when the tool is equipped but even when the tool is unequipped the animations play instead of the ones in the punch script
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried disabling the script from the punch script when its unequipped, but the Animation of the other script still plays.
Some Extra Details:
I have both the punch script and the script for the tool inside a ScreenGui in StarterGui
they are both local scripts
This is in my punch script
BattleAxe is what I named the script for my tool
-- players.PlayerAdded:Connect(function()
script.Parent.BattleAxe.Disabled = true
if plr.Backpack:WaitForChild("BattleAxe").Equipped then
script.Parent.BattleAxe.Disabled = false
if script.Parent.BattleAxe.Disabled == true then
print("BAdisabled")
end
end
end)
And this is in the Script for the Tool
Punches is my punch script
function disable ()
if plr.Backpack:WaitForChild("BattleAxe").Equipped then
script.Parent.Punches.Disabled = true
elseif plr.Backpack:WaitForChild("BattleAxe").Unequipped then
script.Parent.Punches.Disabled = false
if script.Parent.Punches.Disabled == true then
print("Disabled")
end
end
end
The rest of the punch script and tool script are just for playing animations and hitbox.
Well, the problem is there. Even though the equipped/unequipped property seems rather straight forward (which in this case, you’ve probably assumed it to be a boolean), isn’t a typical variable; Matter fact, it’s considered a signal.
If you want to check to make sure if it’s equipped, then you could use the signals like this:
players.PlayerAdded:Connect(function()
--[[
old way:
if plr.Backpack:WaitForChild("BattleAxe").Equipped then
script.Parent.BattleAxe.Disabled = false
if script.Parent.BattleAxe.Disabled == true then
print("BAdisabled")
end
end
]]
-- "proper" way:
plr.Backpack:WaitForChild("BattleAxe").Equipped:Connect(function()
script.Parent.BattleAxe.Disabled = false
if script.Parent.BattleAxe.Disabled == true then
print("BAdisabled")
end
end)
end)
-- disable function
-- [[
old way:
function disable ()
if plr.Backpack:WaitForChild("BattleAxe").Equipped then
script.Parent.Punches.Disabled = true
elseif plr.Backpack:WaitForChild("BattleAxe").Unequipped then
script.Parent.Punches.Disabled = false
if script.Parent.Punches.Disabled == true then
print("Disabled")
end
end
end
]]
-- "proper" way (you wouldn't even need the function)
plr.Backpack:WaitForChild("BattleAxe").Equipped:Connect(function()
script.Parent.BattleAxe.Disabled = false
end)
plr.Backpack:WaitForChild("BattleAxe").Unequipped:Connect(function()
script.Parent.BattleAxe.Disabled = true
if script.Parent.Punches.Disabled == true then
print("Disabled")
end
end)
It works! the only problem is sometimes I have to unequip and reequip the tool for it to work.
I forgot to mention that BattleAxe is the name of the tool script that the code is in, same with the punches.
This is the new code in the tool script.