Hello devs! I was trying to build a Mining System in roblox today. And I am running into some errors.
The problems I’m facing-
- There is uncertainty in mining the ores. I do not understand why.
- I would like to make a collecting system wherein I want to collect the ores there, as tools on my hotbar.
Here are the scripts I used.
LocalScript for the tool
local tool = script.Parent
local anim = tool:WaitForChild("Animation")
local se = tool.Pickaxe.SoundEffect
local plr
local char
local track
local connection
local mouse
local canMine=true
local stringVal
local function onActivated()
local part = mouse.Target
if part and part.Parent.Name == "Deposits" and canMine then
local hrp = char:WaitForChild("HumanoidRootPart")
local dist = (hrp.CFrame.Position - part.Position).Magnitude
if dist<10 then
canMine=false
hrp.Anchored = true
track:Play()
track.KeyframeReached:Connect(function(kfName)
if kfName == "Hit" then
tool.SoundEvent:FireServer()
end
end)
if part.Parent.MineType.Value == "Stone" then
task.wait(3)
end
if part.Parent.MineType.Value == "Gold" then
task.wait(9)
end
if part.Parent.MineType.Value == "Iron" then
task.wait(5)
end
if part.Parent.MineType.Value == "Bronze" then
task.wait(7)
end
tool.CollectEvent:FireServer(part, part.Parent.MineType.Value)
canMine=true
hrp.Anchored=false
track:Stop()
end
end
end
tool.Equipped:Connect(function()
plr = game.Players.LocalPlayer
char = plr.Character or plr.CharacterAdded:Wait()
mouse = plr:GetMouse()
local hum = char:WaitForChild("Humanoid")
track = hum.Animator:LoadAnimation(anim)
connection = tool.Activated:Connect(onActivated)
end)
tool.Unequipped:Connect(function()
plr = nil
char = nil
connection:Disconnect()
end)
ServerScript to collect-
local tool = script.Parent
local SoundEvent = tool:WaitForChild("SoundEvent")
local SoundEffect = tool.Pickaxe:WaitForChild("SoundEffect")
local CollectEvent = tool:WaitForChild("CollectEvent")
local r = Random.new()
min = 1
max = 2
SoundEvent.OnServerEvent:Connect(function(plr)
SoundEffect:Play()
end)
CollectEvent.OnServerEvent:Connect(function(plr, part)
part.Transparency = 1
end)
ServerScript in the model where the ores are-
local deposits = script.Parent:GetChildren()
local mineTypeTemp = deposits.Minetype
for _,v in pairs(deposits) do
local mineType = mineTypeTemp:Clone()
mineType.Parent = v
v:GetPropertyChangedSignal("Transparency"):Connect(function()
if v.Transparency == 1 then
v.CanQuery = false
task.wait(15)
v.Transparency = 0
v.CanQuery = true
end
end)
end
Here is the proper breakup of my Explorer if you are still confused-
These are the tools, which I want to add to the player’s hotbar after mining the ores.
Thank you so much for reading this. Please provide me with a solution. Thanks