How can I give game currency when a player touches a checkpoint object in an obby game?

Hello fellow developers!

I am a novice developer although I have developed several games for last 6 months.

Now I am developing a new obby game and what I want to realize is:

When a player touches a checkpoint (spawn) object, the object color changes and a sound beeps for a few seconds, in addition to display of a small heart and awarded currency amount above the object for a second, while the given currency amount is reflected on a leaderstats only once per one spawn object in a game session.

I modified the checkpoint script in Roblox obby template and wrote some code for the effect.
I also made learderstat script in ServerScriptService.

The problem is because the checkpoint script is not a local script,
I cannot use a remote event.

How can I realize above?
Do I need another local script to use a remote event?
If so, where should I make?
I appreciate if someone show me a good flow or sample scripts.

The below are part of scripts for your reference.

1 Like

You can use bindable events to communicate between server to server or client to client scripts. Though why can’t you just give the currency in the checkpoint script by getting the player and the respective value you want to change?


To add onto Frost, you can also use a module but in this scenario I would exactly do what Frost said.

To do this use: Players | Roblox Creator Documentation to get the player => then increment the leaderstats value.

1 Like

Thank you for your reply.
According to your advice, I am rewriting CheckpointScript as follows:

As you can see, I’ve got the error message:
'IntValue is not a valid member of Script “ServerScriptService.Leaderstats” ’

I think the problem is Line 51, marked with the red frame on above pic,
but I am not sure how to fix it.
I appreciate if you show me some code sample here.

Thank you for your reply.
I found that code is in Line 56 of CheckpointScript as shown on above pic.
Is the place correct? If not, to which line should I move it?

leaderstats is a folder found in the player. So to access it you need to find it in the player instead. I’m not sure if you have defined the player? If not, you can get the player from the touched event like so:

local players = game:GetService('Players')
local debounce = false

	if not debounce then
		local player = players:GetPlayerFromCharacter(hit.Parent) 
		local leaderstats = player:FindFirstChild('leaderstats')
		local money = leaderstats:FindFirstChild('Love')
		money.Value += amount
		debounce = true

Also, I notice that you have defined a few variables at the top of your script that you should consider removing because they will throw errors, as you can’t define them like that:

  • The local player can only fetched through a local script
  • The leaderstats variable can only fetched when you’re getting the player.
1 Like

Now it works beautifully.
Thank you so much.
You are amazing!