Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is this currency script not working?

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

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.

6 comments

0

You can't use PlayerAdded in localscripts.

0

I meant for the method :IsInGroup()

0

IsInGroup() doesn't need to be in a localscript..

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.

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.

0

If statements only run once unless there is a loop or a function being called.

This discussion is preserved as it was. New answers, comments, and votes are closed.