Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why isn't my DataStore saving and how would I fix this?

Asked by 1 year ago

So basically, I made a short project in which a player's JumpPower is increased per click, here are the two scripts:

local datastore = game:GetService("DataStoreService")
local powerStore = datastore:GetDataStore("powerStore")

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local power = Instance.new("IntValue", leaderstats)
    power.Name = "Power"

    local savedata
    local s, f = pcall(function()
        savedata = powerStore:GetAsync(player.UserId)
    end)

    if s then
        power.Value = savedata
        print("data successfully loaded")
    else 
        print("data not loaded")
    end

    player.CharacterAdded:Connect(function(character)
        character.Humanoid.JumpHeight = power.Value
    end)
end)

game.Players.PlayerRemoving:Connect(function(player)
    local s, f = pcall(function()
        powerStore:SetAsync(player.UserId, player.leaderstats.Power.Value)
    end)

    if s then
        print("data successfully saved")
    else 
        print("data not saved")
    end
end)

^ thats the datastore

and this is the GUI:

local button = script.Parent

button.MouseButton1Click:Connect(function()
    game.Players.LocalPlayer.leaderstats.Power.Value += 1
    game.Players.LocalPlayer.Character.Humanoid.JumpHeight = game.Players.LocalPlayer.leaderstats.Power.Value
end)


When I go in the game, and use F9 to change the value of the power, the datastores works just fine and saves the value, however when I use the button to increase it, then it doesn't save/load anything.

1 answer

Log in to vote
1
Answered by 1 year ago

This is due to Filtering Enabled.

Filtering Enabled prevents changes on the client to replicate to the server. Your "Power" value is only being changed on your client and will not be changed on the server. To change it on the server, you can use a Remote Event.

Ad

Answer this question