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

How come this script won't give the player 10000 cash? [SOLVED]

So, I'm using Berezaa's tycoon kit, and it saves the money inside of serverstorage. I wrote this script to try to give +10000 cash if the player has the gamepass, but it won't do anything.

(And yes, I do have the ID defined, it's just in the very first part of the script)

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		
		if game:GetService("GamePassserivce"):PlayerHasPass(player, id) then
			local swag = game.ServerStorage.MoneyStorage.Player.Value
			swag = swag + 10000
		end
	end)
end)

1 comment

0

On line 5 you used Player with a capital P but in line one the functions argument is player with a lower case p

1 answer

✓ Accepted answer

Your error is on line 6. The variable "swag" is saved as the value's data, not the actual value itself. You need to make "swag" the value instance instead of its data. This means you must use swag.Value every time you want to change it. I understand it's a pain, but it's how things must be done.

Check this out:

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)

        if game:GetService("GamePassserivce"):PlayerHasPass(player, id) then
            local swag = game.ServerStorage.MoneyStorage.Player
            swag.Value = swag.Value + 10000
        end
    end)
end)

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