What do you want to achieve? That my (local) script detects if a player joins a team and then do stuff
What is the issue? It’s not doing anything when we come to the part of detecting if the team has changed
What solutions have you tried so far? I’ve tried looking but nothing worked
This is in a local script in StarterGUI
My Code:
local Player = game.Players.LocalPlayer
local Team = game.Teams
if Player.Team == Team.Police then
print("Police!")
end
Provide feedback if needed!
1 Like
jmesrje
(jmesrje)
January 29, 2022, 6:32pm
2
change this line to this:
local Teams = game.Teams
Also put the script in StarterPlayerScripts
I did that but it’s still not printing it To be clear: Teams get changed in a UI (I thought that may be helpful)
EDIT: The code is now this:
local Player = game.Players.LocalPlayer
local Teams = game.Teams
if Player.Team == Teams.Police then
print("Police!")
end
1 Like
jmesrje
(jmesrje)
January 29, 2022, 6:37pm
4
Oh, so if a player presses the police button it will print police?
No, when a player presses that button the team changes. Then it should print that. (Sorry for being so unclear )
xG_andalf
(Gandalf)
January 29, 2022, 6:45pm
7
Hello! Your script isn’t working since it’s in StarterGui and a LocalScript, meaning it only detects a team change on a client (only possible with exploits). Instead, try this Server Script ServerScriptService
game.Players.PlayerAdded:Connect(function(player)
if player.Team.Name == 'Police' then
print(player.Name..' is on the "Police" team!')
end
end)
Please leave a like and mark this as a solution if it solves your problem.
xG_andalf
(Gandalf)
January 29, 2022, 6:46pm
9
Why would this help? This would cause crashes, a coroutine is much better for fixing this issue.
For some reason, this doesn’t work… I don’t get an error or anything. According to the leaderboard in Studio, it does changes
xG_andalf
(Gandalf)
January 29, 2022, 6:48pm
11
Try this instead:
Place this LocalScript in StarterPlayerScripts
function CheckTeam()
if game.Players.LocalPlayer.Team.Name == 'Police' then
print('Police')
end
end
local checkteam = coroutine.create(CheckTeam)
coroutine.resume(checkteam)
Please mark this as the solution if it helps and leave a like!
1 Like
xG_andalf
(Gandalf)
January 29, 2022, 6:49pm
12
What team are they spawning on?
They spawn on the Prisoner team
jmesrje
(jmesrje)
January 29, 2022, 6:49pm
14
He wants it in StarterGui, IMO it doesnt matter if an exploiter changed their team, unless the team has special tools/abilitys
1 Like
jmesrje
(jmesrje)
January 29, 2022, 6:50pm
15
Alright, I’ve found the issue!
Here’s the script
-- Make sure to create the TeamsService!
local Player = game.Players.LocalPlayer
local Teams = game:GetService("Teams")
script.Parent.MouseButton1Down:Connect(function()
player.Team = Teams.Police
print("Police!")
end)
Synitx
(Synitx)
January 29, 2022, 6:50pm
16
jmesrje:
local Teams = game.Teams
How will this help? you have just changed the variable.
2 Likes
xG_andalf
(Gandalf)
January 29, 2022, 6:50pm
17
My way will prevent exploiters. Also you spelt abilities wrong lol
xG_andalf
(Gandalf)
January 29, 2022, 6:51pm
18
That’s wouldn’t work…? He doesn’t want it for GUI? Are you sure your a programmer?
1 Like
jmesrje
(jmesrje)
January 29, 2022, 6:52pm
19
He stated in a previous reply that he did.
Synitx
(Synitx)
January 29, 2022, 6:52pm
20
How a player will be able to be in a team if team doesnt even exists?
He probably have team service or it would show the error.
Its probably because that player isnt in the right team.
jmesrje
(jmesrje)
January 29, 2022, 6:53pm
21
use Instance.new()
or create it in the explorer