I’ve been trying to find a solution to this, however, for some reason, this script that’s supposed to only fire whenever the attribute changes, and detect whether or not a tool is activated, will not work. Below you’ll find the script responsible for this.
Localscript
local AzureOre = script.Parent
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Hitbox = script.Parent:WaitForChild("Hitbox")
local replicatedStorage = game:GetService("ReplicatedStorage")
local OreTouchedEvent = replicatedStorage.OreTouchedEvent
local Character = Player.Character or Player.CharacterAdded:Wait()
local Pickaxe = Character:WaitForChild("Pickaxe")
local Handle = Pickaxe:WaitForChild("Handle")
local Count = 0
local Active = false
Handle:GetAttributeChangedSignal("IsActivated"):Connect(function()
if Handle:GetAttribute("IsActivated") == true then
Active = true
else
Active = false
end
end)
Hitbox.Touched:Connect(function(player)
local function Check()
Count += 1
local Cast = workspace:Raycast(Handle.Position, Handle.CFrame.LookVector * 2)
if Cast then
if Cast.Instance.Name ~= AzureOre.Name then return end
else
return
end
end
repeat task.wait(1) Check() until Count == 5
OreTouchedEvent:FireServer(AzureOre)
Count = 0
end)
Tool script
local Tool = script.Parent
local Handle = Tool.Handle
Tool.Activated:Connect(function()
Handle:SetAttribute("IsActivated", true)
end)
Tool.Deactivated:Connect(function()
Handle:SetAttribute("IsActivated", false)
wait(3)
end)