Problem with if part1 hits part2 then

I am trying to write a script that makes a certain wall disappear when hit by a rolling sphere. First, I wrote this script, which basically spawns the ball in a folder, names it, positions, shapes, and changes its size.

local debounce = false
local function SpawnBall()
	if not debounce then
	 debounce = true
	 
	
		if game.Workspace.spherefolder:FindFirstChildOfClass("Part") then
			game.Workspace.spherefolder:FindFirstChildOfClass("Part"):Destroy()
		end
	 local rollingsphere = Instance.new("Part")
	 rollingsphere.Name = "RollingSphereBall"
	 rollingsphere.Parent = game.Workspace.spherefolder
	 rollingsphere.Position = Vector3.new(-0.399, 19.351, -17.6)
	 rollingsphere.Shape = Enum.PartType.Ball
	 rollingsphere.Size = Vector3.new(4, 4, 4)
	 
	 wait(3)
	 debounce = false
	end
end


game.Workspace.ballregenpart.Touched:Connect(SpawnBall)

But now, I wrote this script, and I want it to be so that when RollingSphereBall (part) touches blockingball (part), then blockingball (part) disappears. I wrote this script but it doesn’t seem to work.

script.Parent.Touched:Connect(function(hit)
  if hit.Name = "RollingSphereBall" then
    script.Parent.CanCollide = false
    script.Parent.Transparency = 0.7
    wait(1.5)
    script.Parent.CanCollide = true
    script.Parent.Transparency = 0
  end
end)

this script doesn’t make the wall walkthrough for the 1.5 sec. I made a separate script for both of these, and put them both in workspace, please help!

the error is in the second line of your second script, you’re using “=” not “==”

local debounce = false

script.Parent.Touched:Connect(function(hit)
    if hit.Name == "RollingSphereBall" and not debounce then
        debounce = true
        script.Parent.CanCollide = false
        script.Parent.Transparency = 0.7

        wait(1.5)

        script.Parent.CanCollide = true
        script.Parent.Transparency = 0
        debounce = false
    end
end)
1 Like

Do I put this into workspace like the first script, or do I put it into the part that I want to disappear when hit?

1 Like

Put the script into the part you want to make disappear when hit.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.