Hi, this is my second question and I would quickly like to say this is a great website and I really appreciate everyone's support. So I have this script and what it does is when the ball touches a part on the goal line it is counted as a goal and the player and ball is teleported to the start which is does. What I want it to do is that once 3 goals are scored it teleports the player and ball to a different place, the script below just teleports the player and ball to the start where as I want to teleport it to a different position. I'm new to scripting so sorry if this is something very basic but I would really appreciate some help, thank you.
Goals = 0 ballname = "Ball" function onTouch(hit) if hit.Name == ballname then wait(0.1) game.Workspace.Ball.CFrame=CFrame.new(-276, 46.4, 163) target = CFrame.new(-262.5, 44.5, 160) for i, player in ipairs(game.Players:GetChildren()) do if player.Character and player.Character:FindFirstChild("Torso") then player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0) Goals = Goals + 1 if Goals == 3 then Goals = true if true then wait(0.1) game.Workspace.Ball.CFrame=CFrame.new(-300, 46.4, 163) target = CFrame.new(-320, 44.5, 160) for i, player in ipairs(game.Players:GetChildren()) do if player.Character and player.Character:FindFirstChild("Torso") then player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0) end end end end end script.Parent.Touched:connect(onTouch)
local Goals = 0 ballname = "Ball" local target = CFrame.new(-262.5, 44.5, 160) local goal2 == false local target2 = CFrame.new(-320, 44.5, 160) function onTouch(hit) if hit.Name == ballname then wait(0.1) hit.CFrame = CFrame.new(-276, 46.4, 163) for i,v in pairs(game.Players:GetChildren()) do if v.Character:FindFirstChild'Torso' then -- removed the "if player.Character" as it was unnecessary, you just need to check if the player.Character has a torso, and if there is no player.Character then it would not work anyways. v.Character.Torso.CFrame = target + CFrame.new(0, i*5, 0)--Replaced vector3.new with CFrame.new, as you cant add CFrame and Vector3. BTW i is undefined, unless you are referring to the i in the pairs loop, if you are then theres really no point as i is == How many players there is, which in this case is pointless. Unless you are trying to multiply the amount of players with 5, then keep going. Goals = Goals + 1 if Goals == 3 then goal2 = true if goal2 == true then wait(0.1) hit.CFrame = CFrame.new(-300, 46.4, 163) if v.Character:FindFirstChild'Torso' then v.Character.Torso.CFrame = target + CFrame.new(0, i*5, 0) end end end end end end script.Parent.Touched:connect(onTouch)
This should be the fixed version, please comment back if it still doesnt work. :)