Group bonus script issue

Hello! I have an issue. I tried adding a group bonus for a game, but instead of giving the players +150 to the value, it sets the value to 150.

This is the script

local group = 5899741
local amount = 150

	local fold ="Folder", player)
	fold.Name = "leaderstats"
	local val ="IntValue", fold)
	val.Name = "Coins"
	if player:IsInGroup (group) then
		val.Value = val.Value + amount

What am I doing wrong? Please be specific, because i’m a scripting noob.

Since you’re creating the value instance right before adding the bonus this is no different than just setting the value to 150 since the new value instance will start with a default value of 0.

You need to have a datastore else your value is going to reset every time when player leaves the game. Maybe that causes the problem because everytime they join the game then value in IntValue is 0 and 0 +150 = 150.

I have a datastore and it works just perfectly, the issue I have is that the script changes the value to 150, instead of giving +150 to the existing one. That’s what I intend to do.

Do you wait for datastore so it does it’s thing before adding the value to the value?

Read the datastore and set the leaderstat value first, then do the group check with the bonus. Otherwise the stored data will overwrite the bonus.

I’m not quite sure about that, but I don’t think it does.

let me see if that works really quick

Make sure that you wait for datastore before adding the value.