Add Scoring A Goal

Learn how to create an awesome online soccer game!

1. In room.js, Add data to the players.

	g.createACharacter('players', client.sessionId,
		{, x, y, score: 0, lives: 3, block3s: 0, block5s: 0 });

This data sets your players lives that they start with, and blocks that they start with.

2. In room.js, Add the kicker.

		kicker: '',

3. In room.js, Add this code to know who kicked the ball last.

		ball.kicker =;

4. In room.js, Add this code so we can update the lives and scores when a goal is made.

		g.handleCollision('goals', 'soccerBalls', (goal, ball) => {
		if (ball.kicker !== {
			g.getACharacter('players', ball.kicker).score += 1;
			g.getACharacter('players', -= 1;
			setTimeout(() => this.addABall(), 3000);

5. In game.js Add a check so we know if the game is over.

	() => {},
	(id, attr, value) => {
		if (id === g.myId() && attr === 'lives' && value <= 0) {

Download your zip, and upload it to, and you should be able to score goals!

Adding Kicking
Add Blocks

Need Help?

Proofread your code, check with your team and classmates, and if you’re still stuck!

Click Here for Help