Leader stats Issue

Well, for some reason, I’ve been having issues with my leaderstats as well all of a sudden.

I can’t see the leaderstats in the studio, but I can in the actual game. This may be a global issue. Or its just a coincidence.

Can you send us a photo of it in the explorer? Are you sure the script isn’t disabled? Furthermore, is this the entire script?

These are the only variables I can think of that would cause the script not to run. Also double check it’s not in ServerStorage instead of ServerScriptService, I’ve made that mistake a couple times.

I’m not sure why it is doing that, I just tried in a baseplate and it seems to work fine.
image

Are you trying this in studio?

If so, then I’m at a loss like the OP is. It just happened all of a sudden…

Yes I am in studio. I think maybe trying to reinstall studio may fix the issue.

1 Like

Ok, oh my gosh. Ok got the cash thing to work. I had to add some stuff then realized it was an issue with studio. I got a question tho…

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Value = 100
	Cash.Parent = leaderstats
end)

That’s my script right now. Now I made a NEW script where I made a part then put a click detector and in that click detector I put a script in that script I made this,

ClickDetector = script.Parent

ClickDetector.MouseClick:Connect(function(player)
	player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1
end)

I was wondering, since usually it’s auto fillable it wasn’t. So why isn’t it sensing the player leaderstats?

Anything is added by a script to part/etc, does not autofill.
Unless its roblox generated.

Got it, let me try this 2nd script out.

Less go it all worked. Question is it possible where I said guys find the block on the map for 1M free cash. BUT then the player spams the click detector, how can I make them only allowed to press it once. AND that they can’t join another server and press it again.

You can use DatastoreService to sync with all servers. Changing the name after its being used or moving to a new game will reset the data allowing players to click it again.

ClickDetector = script.Parent
Datastore = game:GetService("DataStoreService"):GetDataStore("1MFREE_CASH") -- You can rename the datastore to whatever you want

ClickDetector.MouseClick:Connect(function(player)
	if not Datastore:GetAsync(player.UserId) then
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1000000
		Datastore:SetAsync(player.UserId,true)
	end
end)
1 Like

Wa is a data store, I’m a bit confused

https://developer.roblox.com/en-us/api-reference/class/DataStoreService
For more information about datastores: