I want the script to make it so that if the localplayer is in the group, it gives the player 300 cash in leaderstats. The script to do that is not working. (For context, I am the owner of that group.)
(other cash is from another script)
Here is the code:
local Player = game.Players.LocalPlayer
local groupId = 4565262
local minimumRank = 1
if Player:GetRankInGroup(groupId) >= minimumRank then
Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 300
else
print("noob")
end
You’re doing this within a localscript I assume from the local Player = game.Players.LocalPlayer. This will only change it for the client and no one else, see this article..
On a serverscript, put this code:
local groupId = 4565262
local minimumRank = 1
game.Players.PlayerAdded:Connect(function(Player)
if Player:GetRankInGroup(groupId) >= minimumRank then
Player:WaitForChild("leaderstats").Cash.Value += 300
else
print("noob")
end
end)
Okay this is because you are running this code from a localscript, which is the source of your error. If you update A value on the client the server will not recognize / observe what had occured. Instead you want to bridge the gap between server and client by doing this.
So in the localscript you would have …
local player = game.Players.LocalPlayer
local addPointsRemote = game.ReplicatedStorage.AddPoints
addPointsRemote:FireServer() -- this will tell the server that you need to add points
and in the server script you would have something like this
local addPointsRemote = game.ReplicatedStorage.AddPoints
local groupID = 4565262
local minRank = 1
addPointsRemote.OnServerEvent:connect(function(sender)
if sender:GetRankInGroup(groupID) >= minRank then
if sender:FindFirstChild("leaderstats"):FindFirstChild("Cash") then
sender.leaderstats.Cash.Value += 300
end
end
end)
Hope that helps, Boston.
P.S. Just to clarify @Wizrred 's solution works just as well, it just really depends what you are trying to use it for. If you want ti to be something that the user’s client can call upon more than once and won’t just happen when they join the server than you can use my method.
The problem with that method is that exploiters can take control of that remote and give themselves the cash an infinite amount of times. Remember, never trust the client! It’s best to get the player from the server and do everything there instead.