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
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)