So I have 8 bricks. 4 union and 4 parts. When you click the tool it should take away SR1 and SR11 first. Then on the second click it should take away SR2 and S22 etc for 4 clicks. However it only works on the first click then after that I can't click again! Help! Here is the code:
debounce = false Tool = script.Parent local player = game.Players.LocalPlayer repeat wait() until player.Character ~= nil local hum = player.Character:WaitForChild("Humanoid") local animation = script.EatingAnimation local animation2 = script.HoldingAnimation local AnimTrack = hum:LoadAnimation(animation) local AnimTrack2 = hum:LoadAnimation(animation2) Tool.Equipped:connect(function(mouse) mouse.Button1Down:connect(function() if debounce == false then AnimTrack:Play() debounce = true if Tool.SR1.Transparency == 0 or Tool.SR11.Transparency == 0 then Tool.SR1.Transparency = 1 Tool.SR11.Transparency = 1 else Tool.SR2.Transparency = 1 Tool.SR22.Transparency = 1 if Tool.SR2.Transparency == 1 or Tool.SR22.Transparency == 1 then Tool.SR3.Transparency = 1 Tool.SR33.Transparency = 1 else Tool.SR4.Transparency = 1 Tool.SR44.Transparency = 1 end wait(2.1) debounce = false end end end) end) Tool.Equipped:connect(function() if player:IsInGroup(2608221) then AnimTrack2:Play() end end) Tool.Unequipped:connect(function() AnimTrack:Stop() AnimTrack2:Stop() end)
Your if statements within lines 17-30 are not checking for the right conditions. In each if statement, you want to check if a part is transparent, and also if the part after that is not transparent.
You are just checking if they are transparent, which will cause the script to run a scope without checking the other statements.
Fixed Code:
debounce = false Tool = script.Parent local player = game.Players.LocalPlayer repeat wait() until player.Character ~= nil local hum = player.Character:WaitForChild("Humanoid") local animation = script.EatingAnimation local animation2 = script.HoldingAnimation local AnimTrack = hum:LoadAnimation(animation) local AnimTrack2 = hum:LoadAnimation(animation2) Tool.Equipped:connect(function(mouse) if player:IsInGroup(2608221) then AnimTrack2:Play() end mouse.Button1Down:connect(function() if debounce == false then debounce = true if Tool.SR1.Transparency == 0 then Tool.SR1.Transparency = 1 Tool.SR11.Transparency = 1 AnimTrack:Play() elseif Tool.SR1.Transparency == 1 and Tool.SR2.Transparency == 0 then Tool.SR2.Transparency = 1 Tool.SR22.Transparency = 1 AnimTrack:Play() elseif Tool.SR2.Transparency == 1 and Tool.SR3.Transparency == 0 then Tool.SR3.Transparency = 1 Tool.SR33.Transparency = 1 AnimTrack:Play() elseif Tool.SR3.Transparency == 1 and Tool.SR4.Transparency == 0 then Tool.SR4.Transparency = 1 Tool.SR44.Transparency = 1 AnimTrack:Play() end wait(2.1) debounce = false end end) end) Tool.Unequipped:connect(function() AnimTrack:Stop() AnimTrack2:Stop() end)
If I helped you out, be sure to accept my answer!
I believe the problem lies within your conditionals on lines 17-30. You don't end the first one until line 33 which might not be what you want. Also, you were checking to see if SR2 and SR22 were transparent after making them transparent so it would've ran on the first try anyway. The way the script works now is it checks to see which is the highest number of transparent bricks and then makes the next higher one transparent.
debounce = false Tool = script.Parent local player = game.Players.LocalPlayer repeat wait() until player.Character ~= nil local hum = player.Character:WaitForChild("Humanoid") local animation = script.EatingAnimation local animation2 = script.HoldingAnimation local AnimTrack = hum:LoadAnimation(animation) local AnimTrack2 = hum:LoadAnimation(animation2) Tool.Equipped:connect(function(mouse) if player:IsInGroup(2608221) then AnimTrack2:Play() end mouse.Button1Down:connect(function() if not debounce then if Tool.SR4.Transparency ~= 1 and Tool.SR44.Transparency ~= 1 then AnimTrack:Play() end debounce = true if Tool.SR3.Transparency == 1 or Tool.SR33.Transparency == 1 then Tool.SR4.Transparency = 1 Tool.SR44.Transparency = 1 elseif Tool.SR2.Transparency == 1 or Tool.SR22.Transparency == 1 then Tool.SR3.Transparency = 1 Tool.SR33.Transparency = 1 elseif Tool.SR1.Transparency == 1 or Tool.SR11.Transparency == 1 then Tool.SR2.Transparency = 1 Tool.SR2.Transparency = 1 else Tool.SR1.Transparency = 1 Tool.SR11.Transparency = 1 end wait(2.1) debounce = false end end) end) Tool.Unequipped:connect(function() AnimTrack:Stop() AnimTrack2:Stop() end)