I’m trying to create a pickaxe tool for a mining system that I’m creating, but, for some odd reason the pickaxe picks and chooses when it wants to send a raycast. I’ve tried changing the distance, tried going right up to the hitbox limits, however regardless it doesn’t seem to be working most of the time. I’m rather confused on what to do, and any help I get would be most appreciated.
Localscript in charge of sending out the raycast when within the confines of the hitbox
local Rock = 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 params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {workspace:FindFirstChildOfClass("Terrain")}
Pickaxe.Activated:Connect(function()
Hitbox.Touched:Connect(function() end)
local function Check()
for _, part in pairs(Hitbox:GetTouchingParts()) do
Count += 1
local Cast = workspace:Raycast(Handle.Position, Handle.CFrame.LookVector * 2, params)
print(Cast)
if Cast then
if Cast.Instance.Name ~= Rock.Name then return end
else
return
end
end
end
repeat task.wait(1) Check() until Count == 5
OreTouchedEvent:FireServer(Rock)
Count = 0
end)
Unfortunately, there’s no error that I can see. In fact, I recently tried it and the raycasting worked perfectly, but the ore that I wanted it to mine, simply didn’t disappear all the while an ore which was greater than 2 studs away from me got affected??
It only “sometimes work”? Because, i have seen that in the first gif, you showed in a baseplate with a bunch of bolders, the second one, is just a black zone (aka black box)
On the testing place, it does as it supposed to, however, in the actual game it only sometimes does as its supposed to, while the rest of the times I’ve tried it, it does nothing.
The models are the exact same, and I only used the testing place as demonstration, as the ores in the testing place has an outdated script. I’m trying a new implementation using raycast, and for some reason the raycast will not work most of the time.