Soccer script works one place, but not multi places

I have this script for my football/soccer game. It works fine if it’s only 2 goals and the ball is spawning fine.

But If I copy it to another place in my world, it does not re register the goals and does not respawn the ball

I would like to have difference areas in the world where my players can play. But I just can’t see who to fix it.

I can provide more info, if needed :wink:

My setup for it is like this

Soccer

  • Script
local b = script:WaitForChild("Ball")
local nb = b:Clone()
local startPos = b.Position
local ps = game:GetService("PhysicsService")
local ball = ps:CreateCollisionGroup("Balls")
local wall = ps:CreateCollisionGroup("Walls")
ps:CollisionGroupSetCollidable("Default","Balls",true)
ps:CollisionGroupSetCollidable("Default","Walls",false)
ps:CollisionGroupSetCollidable("Balls","Balls",true)
ps:SetPartCollisionGroup(script:WaitForChild("Border"),"Walls")
ps:SetPartCollisionGroup(script:WaitForChild("Border2"),"Walls")
local function resetBall(p,goal)
	if p==b then
		b:Destroy()
		if goal then
			for i=1,3 do
				for i,v in pairs(script.Parent:WaitForChild(goal):GetChildren()) do
					v.Material = Enum.Material.Neon
				end
				script:WaitForChild(goal).Material = Enum.Material.Neon	
				wait(0.5)
				for i,v in pairs(script.Parent:WaitForChild(goal):GetChildren()) do
					v.Material = Enum.Material.SmoothPlastic
				end
				script:WaitForChild(goal).Material = Enum.Material.SmoothPlastic
				wait(0.5)
			end
		end
		b = nb
		nb = b:Clone()
		b.Parent = script
		ps:SetPartCollisionGroup(b,"Balls")
	end
end
resetBall(b)
script:WaitForChild(1).Touched:Connect(function(p)
	wait(0.05)
	resetBall(p,1)	
end)
script:WaitForChild(2).Touched:Connect(function(p)
	wait(0.05)
	resetBall(p,2)	
end)

Is there any error in the output menu? My first thought is perhaps there’s a wrong local in the script. Maybe you accidentally moved something into the wrong parent and the script just can’t find the object and it doesn’t work. Feel free to ask and correct me.

1 Like

Hi. Thanks for your help

The Output does not say anything.
My first idea it just change the name to of the part to another name and also change the name in the script. I have tried this but I can’t make it work.

This first picture is the setup

I have also made a video to show what happens if I just copy all of it to another place

My issue