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

2 Questions with creating a mining game in an FE enabled game?

Asked by
dirk2999 103
5 years ago
Edited 5 years ago

Question 1,

Is this the best way to check if the target block has changed? The mining blocks Name is it's position when it's spawned. Also this is in a tool.

local blockValues = game.ServerStorage.Configuration.block_Values
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local target
local selected_Block = "None"

script.Parent.Equipped:connect(function()
    mouse.Move:connect(function()
        if mouse.Target then
            target = mouse.Target
            if target:FindFirstChild("Type") then
                if selected_Block == tostring(mouse.Target.Name) then
                    print("Same Block!")
                else
                    print("Different Block!")
                    selected_Block = mouse.Target.Name
                end
            end
        end
    end)
end)

Question 2, When I unequip the tool, the script keeps printing. How do I stop the script when they unequip the tool?

1 answer

Log in to vote
0
Answered by 5 years ago

Add a bool that checks if tool is equipped.

local equipped = false

tool.Equipped:Connect(function(mouse)
    equipped = true

    mouse.Move:Connect(function()
        if equipped then
            -- code
        end
    end)
end)

tool.Unequipped:Connect(function() -- Mouse isn’t a parameter for Unequipped
    equipped = false
end)
Ad

Answer this question