Touched Function not working

local Prompt = script.Parent

local Display = script.Parent.Parent.SurfaceGui.Display

Prompt.Triggered:Connect(function(Plr)
	if Plr.leaderstats.Money.Value >= 7 then
		Prompt.MaxActivationDistance = 0
		Plr.leaderstats.Money.Value -= 7
		
		Display.Text = Plr.Name.." is playing..."
		
		ball.Anchored = false
		wait(10)
		ball.Anchored = true
		
		ball.Touched:Connect(function(Color)
			print("Ball hit")
			if Color:IsA("MeshPart") then
				if Color.Name == "Red" then
					print("Red")
				elseif Color.Name == "Green" then
					print("Green")
				elseif Color.Name == "Blue" then
					print("Blue")
				else
					print("Error no color")
				end
			end
		end)
		wait(3)
		ball.Position = Vector3.new(-84.65, 6.801, -226.016)
		Prompt.MaxActivationDistance = 4
		
		Display.Text = "$7 to play."
	else
		
	end
end)

Everything is working with this code except the “ball.Touched” never gets set off I even put a print there to see if it was getting set off but it’s not even printing that, no errors nothing, but I’m trying to get the ball to detect if it hits another part. What do I do? Or what’s wrong with this code?

I believe this is the issue,

So you have an event in an event meaning that only when the prompt is triggered, if the ball is being touched it will fire (to my knowledge)

to fix this you should have your touched event outside of your prompt event and having a bool value being set to true when your prompt is triggered, and the touched event will only run when that bool value is true.

3 Likes

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