#datastore

24 messages · Page 1 of 1 (latest)

dusk summit
#

hi i cant save data with my datastore so i need imput some folder or something else in my game ?

local DataStoreService = game:GetService("DataStoreService")
local energyDataStore = DataStoreService:GetDataStore("EnergyDataStore")
local Click = script.Parent

Click.MouseButton1Click:Connect(function()
-- Load the player's energy value
local player = game.Players.LocalPlayer
local success, energyValue = pcall(function()
return energyDataStore:GetAsync(player.UserId .. "_Energy")
end)

if success then
    -- Use the loaded energy value
    print("Energy value:", energyValue)
else
    -- Handle the error
    print("Failed to load energy value:", energyValue)
end

-- Modify the energy value
energyValue = energyValue + 10

-- Save the modified energy value
local saveSuccess, saveError = pcall(function()
    energyDataStore:SetAsync(player.UserId .. "_Energy", energyValue)
end)

if saveSuccess then
    print("Energy value saved:", energyValue)
else
    print("Failed to save energy value:", saveError)
end

end)

lilac coral
#

because you cant save data with a local script

#

also uh

#

to imagine a button saving data for each click sounds very expensive for the data store service

#

id suggest you stick to saving data only when the player leaves and also ofc via server script

craggy gale
craggy gale
#

with 1 click?

craggy gale
dusk summit
#

UI button

#

when you click you gain x amount of energy

vale sentinelBOT
#

studio** You are now Level 1! **studio

craggy gale
#

yea we can manage that its not hard but to not put a hard time for datastore we can make a cooldown

craggy gale
dusk summit
#

variable

craggy gale
#

i see

#

do u want it to save too?

craggy gale
#

instead u gotta identify the player in other ways

#

local scripts only do for the client not Publicly for the server

#

local scripts are mainly used for doors that only open for the player who got the key

#

Sry typo script* not a local script

craggy gale