Im making a destroying script, and when ever you hold down the mouse it will count untill it breaks. It keeps detecting its up even though its down.
Help?
Code:
--[[
EXTRA INFORMATION:
Parent = game.StarterPack
ScriptType = LocalScript
]]
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local mouseDistance = 30
local distance = nil
local function GetMaxDistance()
distance = (player.Character.HumanoidRootPart.Position - mouse.Target.Position).Magnitude
-- print(distance)
end
function DestroyBlock()
GetMaxDistance()
if mouse.Target.Name == "log" and distance <= mouseDistance then
local logStregth = 5
local setBlock = mouse.Target
print(setBlock)
if mouse.Button2Down then
for i = 0,logStregth,1 do
print(i)
if mouse.Button2Up then
print("Mouse went up")
break
end
if i == logStregth then
setBlock:Destroy()
end
wait(1)
end
end
end
end
function PlaceBlock()
GetMaxDistance()
if distance <= mouseDistance then
local newBlock = game.ReplicatedStorage.Assets.grass:Clone()
newBlock.CFrame = CFrame.new(mouse.Target.Position + Vector3.new(0,4,0))
newBlock.Parent = mouse.Target.Parent
end
end
mouse.Button1Down:Connect(PlaceBlock)
mouse.Button2Down:Connect(DestroyBlock)
