Checkpoint Script Not Working

This is my script, but It doesn’t really work and I might not done something good:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local i = 1

local S = script.Parent
local function BrickTouch(Part)
	local Parent = Part.Parent
	if game.Players:GetPlayerFromCharacter(Parent) then
		Player.Team = "Stage"..i + 1
	end
end

S.Touched:connect(BrickTouch)
4 Likes

I honestly don’t know scripting, but I use a great trusted model, check it out: https://www.roblox.com/library/2786054355

Are the SpawnLocation properties set correctly to spawn a user in a place based on their team?

Oh also, team must be an object, not a string.

Player.Team = game.Teams.Team
-- not
Player.Team = "Team"

Possible example:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Teams = game:GetService("Teams")
local i = 1

local S = script.Parent
local function BrickTouch(Part)
	local Parent = Part.Parent
	if game.Players:GetPlayerFromCharacter(Parent) then
		Player.Team = Teams["Stage"..i + 1]
	end
end

S.Touched:Connect(BrickTouch)

Is this a Localscript, a Serverscript or a Script?

Based on your script. I assume that you’re using the normal script. In which, the script doesn’t work because normal script don’t listen to LocalPlayer command

You might want to do something like this :

local i = 1

local function BrickTouch(Part)
	if game.Players:GetPlayerFromCharacter(Part.Parent) then
		local Player = Part.Parent
		game.Players[Player.Name].Team = tostring("Stage"..i + 1)
	end
end

Extra note : In case the part touch your accessories. It will error. You might want to develop this script

If you just want checkpoints, you don’t really even have to write any code.

Under the Model tab, there’s an option called services


image

You can insert the Teams service
image

That will add a new Teams object to your explorer
image

You can then add new team objects under that folder
image

Set the name and TeamColor using the properties widget
image

Then, using SpawnLocation objects
image

You can set the team color, and to change teams on touch

Every team spawns at their Team SpawnLocation, based on their TeamColor
By setting AllowTeamChangeOnTouch to true, it allows players to switch teams by simply touching the SpawnLocation.

Easy checkpoints

5 Likes

What is ReplicatedScriptService :shock:, first time I noticed that

google it

1 Like

Soo uhh, I just wan’t to say thanks for the help, but It doesn’t quite respawn me at the spawn location and I changed the color of the spawn location too, but still doesn’t work.

Did you change the BrickColor or the TeamColor?
You need to change the TeamColor.
Also, you need to have a new team for each checkpoint.

1 Like

Yes, I know that but I changed the color of the spawn point to the team color and still didn’t work.

you can search it up on the roblox developer hub.
Here is a link : Player | Documentation - Roblox Creator Hub

1 Like

show me a screenshot of your SpawnLocation’s properties
like this: