Coin Counter

How does GetResource() work?
I'm trying to make a coin counter, where each time you get a coin, the counter gets + 1 coin. To do so (I'm new to programming) I'm wathcing a video... The thing is, the video shows the next code:

Task.Wait()
local player = Game.GetLocalPlayer()

function Tick()

local dinero = player:GetResource("Manticoin")
script.parent.text = tostring(dinero or 0)

end

But when I execute it, the coin counter doesn't change when I pick up coins. What does GetResource() do? What is "Manticoin"? And how can I solve this problem?

Thanks

Try this:

--Variables
local TRIGGER = script:GetCustomProperty("Trigger"):WaitForObject()
local COIN = script:GetCustomProperty("Coin"):WaitForObject()

--Función para que la moneda se destruya al ser tocada por un jugador
function GetCoin(trigger, object)
if object ~= nil and object:IsA("Player") then
script.parent.parent:Destroy()
object:AddResource("Manticoin", 1) -- this line will add one more coin to the total
end
end

--Conectar la función con el trigger
script.parent.beginOverlapEvent:Connect(GetCoin)

--Rotación de la moneda
script.parent.parent:RotateContinuous(Rotation.New(0, 0, 174), 1)

To use code blocks, simply add 3 ` before and after the code :smiley:

OMGG!!! THANK YOU SO MUCH!!!! :smiley: :smiley:

Hello :slight_smile:

player:GetResource() would do just that, it would get the resource linked to the player profile. In this case, the resource is called Manticoin.

You can use player:AddResource() to add more coins to the counter.

So in other words, something like the following would apply:

local dinero = player:GetResource("Manticoin")

This part would get the resource linked to the player profile. From here on out, you can use either SetResource() or AddResource() to increase/decrease the amount of coins.

Keep in mind that the code you posted is running in the Tick function and likely not tied to a specific action, like touching the coin, so you would have to do the SetResource() or AddResource() in the script linked to the coin. The example posted seems to be updating a UI counter so there should not be any issues running it.

The change the amount of coins a player has, you can do something like this:

function PickupCoin()
	player:AddResource("Manticoin", 1)
end

You can have a look at the Player API for more information.

Please let me know if you need any more help :slight_smile:

This is the video I'm using:

From minute 4:05 to 4:15 (In minute 4:15 is the code)..
And it works for him, I did everything he did, I made an UI container which contains a Client Context, wich contains a UI container(client), which contains a UI text box(client), which contains the script(client)

In that case, there could be a problem with your Server script not setting the amount of Manticoins correctly or at all.

Can you post the code you used for picking up the coins here so that I can try and help?

--Variables
local TRIGGER = script:GetCustomProperty("Trigger"):WaitForObject()
local COIN = script:GetCustomProperty("Coin"):WaitForObject()

--Función para que la moneda se destruya al ser tocada por un jugador
function GetCoin(trigger, object)
if object ~= nil and object:IsA("Player") then
script.parent.parent:Destroy()
end
end

--Conectar la función con el trigger
script.parent.beginOverlapEvent:Connect(GetCoin)

--Rotación de la moneda
script.parent.parent:RotateContinuous(Rotation.New(0, 0, 174), 1)

How can I insert a code like you did? (so it's easier to read for you)

You are welcome :stuck_out_tongue: You can let me know if you need any more help. I am still learning myself but always willing to help out if I can. happy holidays :blush:

Than you, it seems like, even though you are learning, you are really good at this! Happy holidays :smiley: