I’ve been attempting to create a mining system, and so with that I need to ensure the ore can only be mined if there’s an active pickaxe tool. But, the problem here is that the localscript does not detect the change in attribute, regardless of what I do.
The problematic 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()
if Active == true then
print("Active!")
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
The tool script that changes the attribute.
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)
So can you explain a little more. Is the problematic localscript in the workspace? Localscripts cant run in the workspace unless you use a feature using a Server Script where you set a scripts RunContext to Client
Ok but the tool script that changes the attribute is also a localscript or a script? If its a regular script then the client wont be able to see any changes made to the IsActivated attribute
The localscript that sends a raycast does function, and almost does what I want, but, it isn’t detecting whether the attribute has changed to “Activated” or “Deactivated”.
Can you verify that the attribute is actually being changed on the server and you can see that in the Properties window on the server side?
Your client code also looks very much incomplete to me, can you send the entire script? You also say that your raycast works, indicating that it is passing your Active condition, which is only possible if it does detect the attribute being changed since your Active variable is initially false.
I tried replacing “If Active == true” with “if Handle:GetAttribute(“IsActivated”) == true”, but despite this, it still isn’t firing the rest of the script, so it does nothing when I click using the placeholder pickaxe tool…
Hitbox.Touched:Connect(function(player)
local function Check()
Count += 1
if Handle:GetAttribute("IsActivated") == true then
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
end)
if Handle:GetAttribute("IsActivated") == true then
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