Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

###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)

This discussion is preserved as it was. New answers, comments, and votes are closed.