#tg

11 messages · Page 1 of 1 (latest)

little pendant
#
local CounterDataStore = DataStoreService:GetDataStore("CounterDataStore")
local Player = game.Players.LocalPlayer

local Counter = Player.PlayerGui:WaitForChild("Teleport1"):WaitForChild("Counter")
local CounterValue = Counter.CounterValue
local Teleporter2 = Player.PlayerGui:WaitForChild("Teleport1"):WaitForChild("Teleport2")
local SuccessLabel = Player.PlayerGui:WaitForChild("Teleport1"):WaitForChild("SUCCESS")
local FailGui = Player.PlayerGui:WaitForChild("Teleport1"):WaitForChild("FAIL")

local function UpdateCounterText()
    Counter.Text = "Counter: " .. CounterValue.Value .. "/100"

    if CounterValue.Value >= 100 then
        SuccessLabel.Visible = true
        wait(3)
        SuccessLabel.Visible = false
    end
end

local function ResetCounter()
    CounterValue.Value = 0
end

local function SaveCounterValue()
    if CounterValue.Value == 100 then
        local success, error = pcall(function()
            CounterDataStore:SetAsync(Player.UserId, CounterValue.Value)
        end)
        if not success then
            warn("Failed to save CounterValue:", error)
        end
    end
end

local function LoadCounterValue()
    local success, data = pcall(function()
        return CounterDataStore:GetAsync(Player.UserId)
    end)
    if success and data then
        CounterValue.Value = data
    else
        ResetCounter()
    end
end

UpdateCounterText()

CounterValue.Changed:Connect(UpdateCounterText)
Teleporter2.MouseButton1Click:Connect(function()
    if CounterValue.Value < 100 then
        CounterValue.Value = CounterValue.Value + 1
    end
end)

Player.CharacterRemoving:Connect(SaveCounterValue)
Player.CharacterAdded:Connect(LoadCounterValue)

while true do
    if FailGui.Visible then
        ResetCounter()
    end
    wait(1)
end
``` why isnt my datastore working i have been at this for 5 hours
#

ServerScriptService.Script:5: attempt to index nil with 'PlayerGui' - Server - Script:5

#

thats the error im getting

#

im struggling hard

teal island
#

playergui is nil

#
local Player = game.Players.PlayerAdded:Wait()
#

u can do game.Players.LocalPlayer only in local scripts

little pendant
#

Oh

#

How would I access it in a script not a local script

teal island
#
local Player = game.Players.PlayerAdded:Wait()