So what I want to do is that when a player joins and the player is in a group, they get a reward. However, it is a one time thing and I did this by making a value that saves.

Here is my first server script:

local GroupID = 554897

game.Players.PlayerAdded:Connect(function(player)
	if player:IsInGroup(GroupID) then
		if player:WaitForChild("Group").Benefit.Value == 0 then
			player:WaitForChild("Group").Benefit.Value = 1
			game.ReplicatedStorage.GroupBenefit:FireClient(player)
			player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 2500
		end
	end
end)

Here is my second server script:

local datastore = game:GetService("DataStoreService")
local bob = datastore:GetDataStore("bob")

game.Players.PlayerAdded:connect(function(plr)
	local folder = Instance.new("Folder", plr)
	folder.Name = "Group"
	
	local value = Instance.new("IntValue", folder)
	value.Name = "Benefit"
	 
	value.Value = bob:GetAsync(plr.UserId) or 0
	bob:SetAsync(plr.UserId, value.Value)
	 
	value.Changed:connect(function()
		bob:SetAsync(plr.UserId, value.Value)
	end)
end)

Can someone help fix my problem so that it saves? Thank you! (Also, I think there is more problems than just that, like how it doesn't even give you cash.)

5 comments

0

We can't really help you if you don't specify what's happening instead of just saying it won't save

0

When I join the game on studio, my value changes from 0 to 1? Ok, you understand? Now when I leave studio and play it on studio again, the value is back to 0. I hope this is clear.

0

DataStores don't work in studio. You must go in-game and play it from there. Also, make sure API Services are enabled.

0

And be even more specific. Are there any errors?

0

First, I tried it in-game and it doesn't work. My API Services are enabled. Secondly, there are no errors. If there were, I would have stated it.