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

How do I fix Datastore not saving a value?

Asked by
Kx1xX 0
2 years ago

Hi, I'm trying to add an option to disable or enable global shadow and next time you join you don't have to change the option anymore.

Here the script in ServerScriptService

local DSService = game:GetService("DataStoreService")
local SV= DSService:GetDataStore("SettingsValues")
local Players = game:GetService("Players")
local Storage = game:GetService("ReplicatedStorage")
local SE = Storage:WaitForChild("ShadowsEnabled")
local SD = Storage:WaitForChild("ShadowsDisabled")

Players.PlayerAdded:Connect(function(player)
    local gui = player.PlayerGui
    local settingsoptions = Instance.new("Folder", gui)
    settingsoptions.Name = "option"
    local Shadows = Instance.new("IntValue", settingsoptions)
    Shadows.Name = "Shadows"
    local key = "Volume_"..player.UserId
    SV:GetAsync(key, player.PlayerGui.option.Shadows.Value)
    if player.PlayerGui:FindFirstChild("option").Shadows.Value == 1 then
        game.Lighting.GlobalShadows = false
        print("ONE")
    elseif player.PlayerGui:FindFirstChild("option").Shadows.Value == 0 then
        game.Lighting.GlobalShadows = true
        print("ZERO")
    end
end)

SE.OnServerEvent:Connect(function(player)
    local key = "User-ID"..player.UserId
    local res = SV:SetAsync(key, player.PlayerGui.option.Shadows.Value)
    print("Enabled")
end)
SD.OnServerEvent:Connect(function(player)
    local key = "User-ID"..player.UserId
    local res = SV:SetAsync(key, player.PlayerGui.option.Shadows.Value)
    print("Disabled")
end)

Here the script on Disabling it

local Storage = game:GetService("ReplicatedStorage")
local RE = Storage:WaitForChild("ShadowsDisabled")
local Player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
        script.Parent.Parent.Parent.Parent.option.Shadows.Value = 1
        RE:FireServer(script.Parent.Parent.Parent.Parent.option.Shadows.Value)
end)

And here the script on enabling it

local Storage = game:GetService("ReplicatedStorage")
local RE = Storage:WaitForChild("ShadowsEnabled")
local Player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.Parent.Parent.option.Shadows.Value = 0
    RE:FireServer(script.Parent.Parent.Parent.Parent.option.Shadows.Value)
end)

I'm not sure if it save or not cause it surely print Disabled/Enabled

Answer this question