Problem with mining script

  1. What do you want to achieve? Keep it simple and clear!
    Alright so i did an mining script by an youtube tutorial, for some reason i get this error
  2. What is the issue? Include screenshots / videos if possible!
    image
    Here is it
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I looked on youtube, there everything was fine

My code:

local Rock = script.Parent
local SettingsUI = Rock.Settings

local swingsLeft = 15

local function onTouch(otherPart)
	local tool = otherPart.Parent
	
	if tool:IsA('Tool') and tool.Mining.Value == true then
		swingsLeft -= 1
		SettingsUI.Frame.OreName.TextLabel.Text = "Coal Ore ("..swingsLeft.."/15)"
		SettingsUI.Frame.HealthFrame.Frame.Frame:TweenSize(UDim2.new(swingsLeft/10,0,1,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1, true)	
	end
	if swingsLeft <= 0 then
		Rock:Destroy()
		Rock.Parent.Union:Destroy()
	end
end

Rock.Touched:Connect(onTouch())
1 Like

Rock.Touched:Connect(onTouch())

You mean

Rock.Touched:Connect(onTouch)

otherPart is a tool handle from a tool

image

yeah just noticed, i’ve edited the post, you were actually calling the onTouch function with nil variable.

functions can be called without putting () in the events.
Example:

function go(hit)
   print(hit) -- works
end
part.Touched:Connect(go)
1 Like

Oh just noticed that, solved thanks

Alright nvm, for some reason now anything don’t work

Output? any errors?
Can you please provide a detail explaination?

Ok nvm, it touches, i just made an error in code sorry

Bruh it sometimes works, sometimes no

Oh alright, player touching ore, not tool,

Because you made the function to detect whenever the Rock is touched.
image