My Local Script Inside Screen Gui " Testing " https://i.gyazo.com/dd2417159cc577ed4a0850adb7fdd9cd.png
Inside local script " UpgradClick" - The mouse button down and up are the only code that are associated with give player a cookie...the upgrades add cookies per click....at baseline with no upgrade when the decal cookie image is clicked it gives player 1 cookie....
-- Variables local cookiev = script.Parent.ckiesv local rebirthv = script.Parent.rbv local cookie = script.Parent.cookie local upg1 = script.Parent.Box.upg1 local plr = game.Players.LocalPlayer local upg2 = script.Parent.Box.upg2 local upg3 = script.Parent.Box.upg3 local tip = script.Parent.TextLabel local sug1 = script.Parent.Box.sug1 local rb1 = script.Parent.rb1 local cc = true local wt = script.Parent.wt cookie.MouseButton1Down:Connect(function() if cc == true then cc = false cookie.Size = UDim2.new(0,250,0,250) plr.leaderstats.Cookies.Value = plr.leaderstats.Cookies.Value + cookiev.Value tip.Visible = true tip.Text = ("+"..cookiev.Value.." cookies") cookie.Rotation = math.random(-30,30) tip.TextColor3 = Color3.new(math.random(0,255)/255, math.random(0,255)/255, math.random(0,255)/255) wait(script.Parent.wt.Value) cc = true end end) cookie.MouseButton1Up:Connect(function() cookie.Size = UDim2.new(0,300,0,300) tip.Visible = false cookie.Rotation = 0 end) upg1.MouseButton1Click:Connect(function() if plr.leaderstats.Cookies.Value >= 50 then plr.leaderstats.Cookies.Value = plr.leaderstats.Cookies.Value - 50 cookiev.Value = cookiev.Value + 5 end end) upg2.MouseButton1Click:Connect(function() if plr.leaderstats.Cookies.Value >= 150 then plr.leaderstats.Cookies.Value = plr.leaderstats.Cookies.Value - 150 cookiev.Value = cookiev.Value + 15 end end) upg3.MouseButton1Click:Connect(function() if plr.leaderstats.Cookies.Value >= 250 then plr.leaderstats.Cookies.Value = plr.leaderstats.Cookies.Value - 250 cookiev.Value = cookiev.Value + 25 end end) sug1.MouseButton1Click:Connect(function() if plr.leaderstats.Cookies.Value >= 5000 then plr.leaderstats.Cookies.Value = plr.leaderstats.Cookies.Value - 5000 wt.Value = wt.Value - 0.1 if wt.Value <= 0 then sug1.Visible = false end end end) rb1.MouseButton1Click:Connect(function() if plr.leaderstats.Cookies.Value >= 2000000 then plr.leaderstats.Cookies.Value = plr.leaderstats.Cookies.Value - 2000000 cookiev.Value = cookiev.Value * 1.3 plr.leaderstats.Rebirths.Value = plr.leaderstats.Rebirths.Value + rebirthv.Value end end)
Whats Inside My Server Script Service ( https://i.gyazo.com/7a165e7345dffa90379fe08a77dc5890.png)
Inside Script " leaderboard"
local datastore = game:GetService("DataStoreService") local ds1 = datastore:GetDataStore("CookiesSaveSystem") function savetablefunc(player)--a table is much more efficient for saving local savetable = { cookies = player.leaderstats.Cookies.Value, rebirths = player.leaderstats.Rebirths.Value } return savetable end game.Players.PlayerAdded:Connect(function(player) local clone = script.leaderstats:Clone()--here we clone the files over clone.Parent = player local save = savetablefunc(player) local savedstuff = ds1:GetAsync(player.userId) function datapull(player,save) -- here we pull the saved data into the ints we cloned player.leaderstats.Cookies.Value = savedstuff.cookies player.leaderstats.Rebirths.Value = savedstuff.rebirth end datapull(player,save) end) function savedata(player) --this is just the function to call on leaving local save = savetablefunc(player) ds1:SetAsync(player.userId,save) end game.Players.PlayerRemoving:Connect(savedata)-- here we save the data on player leaving, you dont need on change its wasteful in most cases
Add a remote event named CookieEvent into replicated storage. This should work, you'll have to figure out the rest from here. Just replicate what I did and adjust as needed.
Server Script
local datastore = game:GetService("DataStoreService") local ds1 = datastore:GetDataStore("CookiesSaveSystem") function savetablefunc(player)--a table is much more efficient for saving local savetable = { cookies = player.leaderstats.Cookies.Value, rebirths = player.leaderstats.Rebirths.Value } return savetable end game.Players.PlayerAdded:Connect(function(player) local clone = script.leaderstats:Clone()--here we clone the files over clone.Parent = player Cookies = player.leaderstats.Cookies local save = savetablefunc(player) local savedstuff = ds1:GetAsync(player.userId) function datapull(player,save) -- here we pull the saved data into the ints we cloned player.leaderstats.Cookies.Value = savedstuff.cookies player.leaderstats.Rebirths.Value = savedstuff.rebirth end datapull(player,save) --here we wait for the remote event, then determine what to do game.ReplicatedStorage.CookieEvent.OnServerEvent:Connect(function(cookiev) Cookies.Value = Cookies.Value + cookiev.Value end) end) function savedata(player) --this is just the function to call on leaving local save = savetablefunc(player) ds1:SetAsync(player.userId,save) end game.Players.PlayerRemoving:Connect(savedata)-- here we save the data on player leaving, you dont need on change its wasteful in most cases
Local Script
cookie.MouseButton1Down:Connect(function() if cc == true then cc = false cookie.Size = UDim2.new(0,250,0,250) game:GetService("ReplicatedStorage").CookieEvent:FireServer(cookiev)--firing remote event from the client tip.Text = ("+"..cookiev.Value.." cookies") cookie.Rotation = math.random(-30,30) tip.TextColor3 = Color3.new(math.random(0,255)/255, math.random(0,255)/255, math.random(0,255)/255) wait(script.Parent.wt.Value) cc = true end end)