Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Making A Clicker Game And Have This I Cant Figure Out How To Make Work?

so im trying to make a clicker game where it saves the price of what your item is at but the datastore is too confusing for me ive looked on youtube but i dont understand it could someone please help also there are 2 scripts

this is the script thats for the item its a local script in a starter gui

button = game.StarterGui.Shop.Frame.ImageButton
player = game.Players.LocalPlayer
cost = game.ReplicatedStorage.StatFile.LocalPlayer.statnumbers.cost1.Value
add = 1

button.MouseButton1Down:connect(function()
	if player.leaderstats.Money.Value >= cost then
		player.leaderstats.Money.Value = player.leaderstats.Money.Value - cost
		player.leaderstats.MPS.Value = player.leaderstats.MPS.Value + add
		cost = cost + 50
	end
end)


while true do
	wait(0.01)
	script.Parent.Text = "Cost: "..cost
end

6 comments

0

please use a code block

0

Please use more, ideally the whole script

0

ive never used this before so i dont know how to

0

Click on the blue Lua code block and paste the code in between the tildes

0

there ive fixed it

0

So basically, you need a DataStore? I'm kinda confused by your question but if you need a DataStore I can help you out.

1 answer

So you need an easy to understand and use DataStore script to save your leaderboard? Worry not, got just the right tool for you, saves automatically the values and names!

Just put this in a SCRIPT in Workspace


game.Players.PlayerRemoving:connect(function(player)
	local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")--Player key

local statstorage = player:FindFirstChild("leaderstats"):GetChildren()
for i =  1, #statstorage do
	datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
	
end
end)


game.Players.PlayerAdded:connect(function(player)
		local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")
	
	player:WaitForChild("leaderstats")
	wait(1)
	local stats = player:FindFirstChild("leaderstats"):GetChildren()
	for i = 1, #stats do			
	stats[i].Value = datastore:GetAsync(stats[i].Name)
		end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.