Help With Touch Event

I am trying to make a script where a ball hits a part and when it does hit, the ball disappears and 3 particles turn on.

The problem is when the ball hits that part, nothing happens and no errors are poping up

the script is in that part

local ball = game.Workspace:WaitForChild("Ball")
local part = script.Parent

local particleA = script.ParticleEmitterA
local particleB = script.ParticleEmitterB
local particleC = script.ParticleEmitterC

function onTouch()
	if (ball ~=nil) then
		ball.Transparency = 1
		ball.Highlight.OutlineTransparency = 1
		particleA.Parent = part
		particleB.Parent = part
		particleC.Parent = part
	end
end

You forgot the ball.Touched

local ball = game.Workspace:WaitForChild("Ball")
local part = script.Parent

local particleA = script.ParticleEmitterA
local particleB = script.ParticleEmitterB
local particleC = script.ParticleEmitterC

function onTouch()
	if (ball ~=nil) then
		ball.Transparency = 1
		ball.Highlight.OutlineTransparency = 1
		particleA.Parent = part
		particleB.Parent = part
		particleC.Parent = part
	end
end

ball.Touched:Connect(onTouch)
local ball = game.Workspace:WaitForChild("Ball")
local part = script.Parent

local particleA = script.ParticleEmitterA
local particleB = script.ParticleEmitterB
local particleC = script.ParticleEmitterC

script.Parent.Touched:Connect(function(Hit)
	if Hit.Name == ball.Name then
		ball.Transparency = 1
		ball.Highlight.OutlineTransparency = 1
		particleA.Parent = part
		particleB.Parent = part
		particleC.Parent = part
	end
end)

I think this is what you wanted to script

it wont work according to how he wants it to be

Ok Kaiden you script works but when I use two of them it does makes both of the part to it.

Xerto, when I used the script nothing happens

Hi, is this a local script or server script?

local debounce = false
script.Parent.Touched:Connect(fucntion(ball)
	if debounce then return end
	debounce = true 
	if ball.Name == "Ball" then -- No need to define ball before we need it.
		ball.Transparency = 1
		local highlight = hit:FindFirstChildOfClass("Highlight")
		if highlight  then
			ball.Highlight.OutlineTransparency = 1
			script.ParticleEmitterA.Parent = ball
			script.ParticleEmitterB.Parent = ball
			script.ParticleEmitterC.Parent = ball
		end
	end
	debounce = false
end)
  • Make sure to turn on the particles
  • Make sure to delete the ball after touched after er certain amount of time if that is intended.

That did not work but after along time i cam up with this but and error comes up

IsPointInRegion is not a valid member of Part "Workspace.Ball" 

How do I fix this error

-- SERVER SCRIPT LOCATED IN SERVERSCRIPTSERVICES
-- Get references to the ball and particle effects
local ball = game.workspace:WaitForChild("Ball")
local partO = game.workspace:WaitForChild("PartO")
local partB = game.workspace:WaitForChild("PartB")
local particle1 = partO.Attachment.ParticleEmitter
local particle2 = partB.Attachment.ParticleEmitter

-- Function to handle the ball's collision
function onTouch()
	if ball ~= nil then
		-- Check which part the ball is touching
		local ballTouchingPart = nil
		if ball:IsPointInRegion(partO.CFrame.Position) then
			ballTouchingPart = "PartO"
		elseif ball:IsPointInRegion(partB.CFrame.Position) then
			ballTouchingPart = "PartB"
		end

		if ballTouchingPart == "PartO" then
			-- Turn on the particle effect for PartO
			particle1:Clear()
			particle1:Emit(10)
			wait(1)
			-- Disable the ball's visibility for Part)
			ball.Transparency = 1
			ball.Highlight.OutlineTransparency = 1
		elseif ballTouchingPart == "PartB" then
			-- Turn on the particle effect for PartB
			particle2:Clear()
			particle2:Emit(10)
			wait(1)
			-- Disable the ball's visibility for PartB
			ball.Transparency = 1
			ball.Highlight.OutlineTransparency = 1
		end
	end
end

-- Connect the collision function to the ball
ball.Touched:Connect(onTouch)

I figured it out I uses one script is ServerScriptServices

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