Help with code regarding a basketball game

Ok, so I’m attempting to make a basketball game, how do I teleport players because they’re on a certain team, for example; team 1 scores so they get teleported to their side and team two gets teleported to their side. How’d I do that?
Ok, and than, how would I make it so only the ball can make the score, and not the players hitting it?

In all seriousness, we cannot write your game for you. In order to create something cool, you have to put effort into it. The forums exist for users to post code and receive help, not the other way around.

5 Likes

These are the only two dilemas I have, everything else I have down.

Spend some time reading documentation and fiddling around with this. A few searches and some experimentation can very easily produce a result for you. As this is not a write-my-code category, I will take your question literally and tell you how you can achieve what you’re looking for.

In order to teleport players of a team to a certain side, first you need your teams to be defined. When you have your teams in the game, use the function of the Team class called GetPlayers which returns an array. Iterate over this array and make sure each player has a character and the character has a root part. If both are true, move them to a specific position by setting the CFrame of their HumanoidRootPart. All of this should be included in a function that’s ran when a score on a net is made.

In order to only allow the ball to make a score and not players, this is simple and you literally answered your own question by asking it. What are your parameters? Only a ball should score on the net. Sound logical to just check if what hit the net is the ball?

There you go.

3 Likes

Thank you so much! It really helps when people explain things to me rather than just giving me the answer! :slight_smile: I really appreciate it!

1 Like

And yeah, I feel stupid. I could do something like

game.workspace.ball = ball
game.team1scorepart = team1score
function Ontouched(ball,team1score) 

and then the rest of the code would probably work :stuck_out_tongue:

Sorry you probably know but the variables are the wrong way around… but if you’re trying to set the parent type .Parent at the end.

(And always remember is your question has been answered mark the reply as a solution, it helps everyone. :))

wdym? Please explain. :slight_smile:

Should be

ball = game.Workspace.ball
team1score = game.team1scorepart

HAHA im so dumb sometimes. Thanks for pointing that out! :joy: what a brainfart

Never say you’re dumb, you aren’t at all, just a bit new. We all make mistakes, remember that. :slight_smile:

2 Likes

This can esaily be done if you know how to manage the team players in workspace folder. If you do this to know which player is in which team then you esaily do:

for i,v in pairs (workspace.TeamRedFolder:GetChildren()) do
 if v[i]:FindFirstChild("HumanoidRootPart") then 
     v[i]:FindFirstChild("HumanoidRootPart").CFrame = CFrame.new(Vector3.new(1,1,1)) -- You change position here 
    end
end

I hope this helps. :herb:

1 Like