Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this mousebutton1 script repeat itself?

Asked by 1 year ago

So I'm making an axe script for a simulator alike game, and what's supposed to happen is that if you stand in front of a tree and press MB1 the Axe would play the classic "roblox sword animation" and destroy the tree. It works as expected, except for the fact that whenever the tree respawns I don't have to click for the same thing to happen again. Please help!

Script inside the axe:



local player = game.Players.LocalPlayer local char = player.Character or player.CharacterAdded:Wait() local Backpack = player.Backpack local Tool = Backpack.DefaultAxe local mouse = player:GetMouse() local scan = script.Parent.Parent.scan Tool.Equipped:Connect(function() mouse.Button1Down:Connect(function() local a = script.Parent.animation local MouseTarget = mouse.Target local anim = Instance.new("Animation") local humanoid = char:WaitForChild("Humanoid") anim.AnimationId = "rbxassetid://80395075" local animator = humanoid:FindFirstChildOfClass("Animator") local track = animator:LoadAnimation(anim) local part = "scanpart" scan.Touched:Connect(function(hit) if hit.Name == part then track:Play() hit.Parent:Destroy() end end) end) end) mouse.Button1Down:Connect(mouse)

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

I fixed it by using both Tool Activation and Touched but separating the two functions inside the same script.

Ad

Answer this question