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

How To Make A Function Restart After mouse.Target Changed?

Asked by
crueluu 169
4 years ago

How Do I Make A Certain Function Reset Before Finishing After The Mouse.Target Has Changed? Heres The Script Just Incase:

local replicatedstorage = game:GetService("ReplicatedStorage") 

                 local run = game:GetService("RunService")
  local Player = game.Players.LocalPlayer
                                        local mouse = Player:GetMouse()
          local billBG = replicatedstorage:WaitForChild("BlockTag") 
                                                                     local down

run.RenderStepped:Connect(function()
    if mouse.Target ~= nil then
        if mouse.Target.Parent == game.Workspace.Blocks then
            billBG.Parent = mouse.Target
            print("BlockHoveredOn!")
        else
                billBG.Parent = replicatedstorage
                print("No Destroy-Able Blocks Found")
                wait(1)
        end
    end

    mouse.Button1Down:Connect(function()
        down = true

      for _,child in pairs(billBG:GetChildren()) do
        child.Visible = true
    end



    end)
    ------------------------------------------------------------------------- ...
    mouse.Button1Up:Connect(function()
        down = false

      for _,child in pairs(billBG:GetChildren()) do
        child.Visible = false
    end



    end)
     while down do
        wait(0.01)
        while mouse.Target do
            wait(0.0001)
              if mouse.Target.Parent == game.Workspace.Blocks then
            wait(2)
        mouse.Target:Destroy()

        end
        end

Answer this question