Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this currency script not working?

Asked by 10 years ago

So this script is supposed to give cash if you are in a certain group. However, it's not giving that cash. Can someone help me please?

Here's the script:

function onPlayerEntered(newPlayer)
    if newPlayer:IsInGroup(0000000) then ----Replace the 0's with the actual group ID
        newPlayer.leaderstats.Cash.Value = newPlayer.leaderstats.Cash.Value + 1000
    end
end

game.Players.PlayerAdded:connect(onPlayerEntered)

1 answer

Log in to vote
0
Answered by 10 years ago
game.Players.PlayerAdded:connect(function(newPlayer)
    if newPlayer:IsInGroup(0000000) then ----Replace the 0's with the actual group ID
local leaderboard = Instance.new("IntValue", newPlayer)
leaderboard.Name = "leaderstats"
local Cash = Instace.new("IntValue")
        Cash.Value = Cash.Value + 1000
Cash.Parent = leaderboard
Cash.Name = "Cash"
    end
end)

Maybe the problem is that leaderboard and cash doesn't exist? Maybe check your output incase this is just a part of a script. Also use a local script for the method :IsInGroup() because If someone leaves the group in-game (why would they?) then it would automatically update.

0
You can't use PlayerAdded in localscripts. Thetacah 712 — 10y
0
I meant for the method :IsInGroup() EzraNehemiah_TF2 3552 — 10y
0
IsInGroup() doesn't need to be in a localscript.. Thetacah 712 — 10y
0
I know but lets say they leave the group while they play the game, which no one would do, but if they did, the local script would automatically update. EzraNehemiah_TF2 3552 — 10y
View all comments (2 more)
0
Nevermind my last comment. I have a leaderboard up, and the script is not a localscript. Apparently, the script only works once, then doesn't work again. CoolJohnnyboy 121 — 10y
0
If statements only run once unless there is a loop or a function being called. EzraNehemiah_TF2 3552 — 10y
Ad

Answer this question