So basically what I’m trying to do is an ATM robbery which is working fine, but then I wanted to add that only Criminals can rob, if police robs it he gets nothing, the problem is I spawn in Neutral team and change to police, when I rob from police team I get nothing which is what I want, but then when I change to Criminal same thing happen, I get nothing.
How to fix this ?
local Police = game.Teams.Police
local Criminal = game.Teams.Criminal
local prompt = script.Parent
local PressEToRob = script.Parent.Parent
local ATMScreen = PressEToRob.Parent.ATMScreen
local MoneyYouGetFromRobbing = 700
local NextRobbWaitTime = 5
prompt.Triggered:Connect(function(player)
print(player.Team)
local PlayerTeam = player.Team
if PlayerTeam == Criminal then
player.PlayerGui.ATMRobbery.MoneyRobbedText.Visible = true
player.leaderstats.Money.Value = player.leaderstats.Money.Value + MoneyYouGetFromRobbing
prompt.Enabled = false
ATMScreen.Color = Color3.new(1, 0.164706, 0)
wait(3)
player.PlayerGui.ATMRobbery.MoneyRobbedText.Visible = false
task.wait(NextRobbWaitTime)
prompt.Enabled = true
ATMScreen.Color = Color3.new(0.0156863, 1, 0)
end
end)
What if you try changing the players team on a server script. Because it looks like when you change the players team it doesn’t go through the server. So when you check what the players team is on the server, it will return the same value as before
Always change teams with Server Script. Only then will the Server Script used for ATM recognise that the player is in a different team since it was changed through the server which replicates everywhere.
The issue with your script is the fact that the player’s team is being changed on the client. Changing important things such as the player’s team is a horrible idea for functionality because that change will not be replicated to the server meaning that everyone else playing and the server will not be able to see that you are on a different team. If the team change must involve the client it is smart to set up what is known as a Remote Event for the player’s team change so it will be replicated to the server. If you do not know what a remote event Is you can research what it is here: Information On Remote Events
A Side Note:
Furthermore, if your game does require multiple robbable ATMs it’s smart to move some of the ATM robbery code to a module script that would handle ATM robbery. This is because Module scripts are super helpful when it comes to code that multiple instances can share.
If You Need Any Help Or Information Contact: R7#9317