#Save local data changes

1 messages · Page 1 of 1 (latest)

fading niche
#

I have this script, where it changes the value of my leaderstats.Wins and hiddenData.unlockedWorld, but because it's a LocalScript, it doesnt save when I leave. I've tried multiple methods such as ReplicatedStorage etc.. but nothing worked, the data always gets reset. Can anybody help?

confirm.MouseButton1Up:Connect(function()
    if wins.Value >= Cost then
        unlockedWorld.Value = worldToBeUnlocked
        wins.Value = wins.Value - Cost
        mainFrame.Visible = false
        -- update gui
        local PlayerGui = Player.PlayerGui.ScreenGui
        local winGui = PlayerGui.Wins
        winGui.Text = "🏆 WINS: " .. wins.Value
    end
end)
inner shale
#

remote event

fading niche
#

I tried setting it Async using a remote event in replicated storage paired with a script in serverscriptservice

#
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")

local winDataStore = DataStoreService:GetDataStore("PlayerWins") -- DataStore initialisieren
local saveLocalData = ReplicatedStorage:WaitForChild("SaveLocalData") -- RemoteEvent laden

saveLocalData.OnServerEvent:Connect(function(player, value)
    if typeof(value) == "number" then -- Überprüfe, ob die Daten valide sind

        local success, errorMessage = pcall(function()
            winDataStore:SetAsync(player.UserId, value)
        end)

        if success then
            print("Daten erfolgreich gespeichert!")
        else
            warn("Fehler beim Speichern der Daten:", errorMessage)
        end
    else
        warn("Ungültige Daten vom Spieler:", player.Name)
    end
end)
#

and then within the LocalScript this:

-- save data
        local replicatedStorage = game:GetService("ReplicatedStorage")
        local saveLocalData = replicatedStorage:WaitForChild("SaveLocalData")
        saveLocalData:FireServer(Player.leaderstats.Wins.Value)```

but it didnt work
young sparrow
#

Man

#

Don't save every damn time

#

And don't trust client at all

#

So don't save anything client sends

fathom bramble
#

DataStore only saves changes done on the server side, not the client.

waxen stump
young sparrow
#

Altho it's defo bad take tho

fathom bramble
#

If it's fine with you

young sparrow
#

Every time it sends..

waxen stump
#

yes save should be made like every 1-5 minutes, when player leaves and when server closes

#

from there no more

fathom bramble
amber kettleBOT
#

studio** You are now Level 11! **studio

fading niche
#

So basically, when the player purchases the door to the next world, the LocalScript removes Wins (the cost for the door) from him and adds 1 to the players World Value. Then it fires a Remote to SetAsync Wins and World

fathom bramble
fathom bramble
#

You have to make this change on the server instead.

fading niche
#

I can try tho to edit the values on a server sided script

#

The problem is, currently, my confirmation button for the purchase, which edits the values, works without specifiyng, which one of the 5 doors on my server should be bought.

However, if I put it on the server side, I would have to specify in detail which world will be unlocked, which will increase the functions size by like 5x

#

It's hard to explain

young sparrow
#

Buddy

#

U need to rewrite all your shit

#
  1. Mousebutton1up doesn't work in server script
#

.

fading niche
young sparrow
#

U are saving stuff on client

#

Rewrite all

fading niche
amber kettleBOT
#

studio** You are now Level 2! **studio

fading niche
#

If I rewrite it it's gonna be exactly the same bcs i dont know how to do it another way

#

I guess i'll try with a click detector then idk

young sparrow
#

U supposed to not do shit on client

#

U changing wins on client

#

Never fucking do that

fathom bramble
#

Inputs are only registered on client.

#

Unless Im stupid

#

You have to use remotes to communicate when the button is pressed.

#

Now I will be busy so others will have to help you.

fading niche
#

I know that changing the wins on local is bad

#

so i tried to do it server side using remote

fading niche
young sparrow
#

U supposed to not keep things on client

#

At damn all

#

U gonna increase wins and do checks on server

#

And not on client

fading niche
#

Yea I understand but then how am I gonna do the gui and wall unlocking thing

#

The unlocking of walls/gates has a confirmation gui which is client sided, that's my issue rn because idk how connect that with the checks and wins-changed on the server side

young sparrow
young sparrow
#

Its like remote but can return

#

So when player tries to buy

#

It fires remote function

#

Server checks if has coins etc then returns true

#

And client removed the wall

fading niche
fading niche