#datastore and timer not working on roblox

1 messages · Page 1 of 1 (latest)

spice cipher
fair furnace
#

can you share the code

#

if you are creating the timer on player add, I would reccomend changing it to character add which will retrigger when the player respawns @spice cipher

spice cipher
#

ill share the code

#
local HealthText = HealthDisplay.TextLabel
----------<TIME>-------------
local timeDisplay = game.ServerStorage:WaitForChild("TimeGui")
local timeText = timeDisplay.TextLabel
-------------------------><CLONE DISPLAY><-----------------------------
game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(character)
        ----------------- HEALTH DISPLAY --------------------
     local character = plr.Character
     local head = character:FindFirstChild("Head")
     local humanoid = character:FindFirstChild("Humanoid")
     ----------------------- <>----------------------------------
     
     ---------------- TIME DISPLAY ----------------------------
     local leaderstats = plr:FindFirstChild("leaderstats")
     local Time = leaderstats:WaitForChild("Time Alive")
     
     
     -----------------------------------------------------------
     
        local RunService = game:GetService("RunService")
        local tD = timeDisplay:Clone()
        tD.Parent = head
        tD.Adornee = head
        RunService.Heartbeat:Connect(function()
            
            tD.TextLabel.Text = Time.Value
        end)
      
     
     local Display = HealthDisplay:Clone()
        Display.Parent = head
        Display.Adornee = head
     local HealthText = Display:WaitForChild("TextLabel")
     
        RunService.Heartbeat:Connect(function()
            HealthText.Text = humanoid.Health.." HP"

            if humanoid.Health >= 60 then
                HealthText.TextColor3 = Color3. fromRGB(99, 255, 99)
            end

            if humanoid.Health <= 60 then
                HealthText.TextColor3 = Color3. fromRGB(255, 253, 130)
            end

            if humanoid.Health <= 30 then
                HealthText.TextColor3 = Color3. fromRGB(255, 52, 55)
            end
        end)
     
    end)
    
end)```
#

@fair furnace

brazen marten
spice cipher
#

it glitched

#

a bit

#

but there are no errors

fair furnace
#

its because the heartbeat function doesnt update

#

since you create the reference outside

spice cipher
fair furnace
#

@spice cipher

#

oh what plugin r u using

spice cipher
#

its not enabled

#

how do i create the reference inside?

#

If you look in the video it doesnt even show

#

as a buildboard gui

fair furnace
#

wdym

spice cipher
#

did you watch the video

spice cipher
fair furnace
#

oh u meant like how it doesnt show in roblox

spice cipher
#

yeah

#

it all works but not in roblox

#

and data store also breaks in roblox

#

i did a data store with my previous learning

#
local TimeDataStore = DataStoreService:GetDataStore("TimeDataStore")

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

    local Time = Instance.new("IntValue")
    Time.Name = "Time Alive"
    Time.Value = 0
    Time.Parent = leaderstats
    
    local Data
    local success, err = pcall(function()
        Data = TimeDataStore:GetAsync(tostring(plr.UserId))
    end)
    
    if success and Data then
        Time.Value = Data
    end
    
    task.wait(3)
    local function isPlayerInZone()
        local character = plr.Character
        if not character then return false end
        local hrp = character:FindFirstChild("HumanoidRootPart")
        local zone = game.Workspace:FindFirstChild("SafeZone")
        if not hrp or not zone then return false end

        -- Check if the player's HumanoidRootPart is within the zone's bounds
        local pos = hrp.Position
        local zPos = zone.Position
        local zSize = zone.Size / 2

        if math.abs(pos.X - zPos.X) <= zSize.X and
            math.abs(pos.Y - zPos.Y) <= zSize.Y and
            math.abs(pos.Z - zPos.Z) <= zSize.Z then
            return true
        end
        return false
    end

    while true do
        if not isPlayerInZone() then
            Time.Value = Time.Value + 1
            local success, err = pcall(function()
                TimeDataStore:SetAsync(tostring(plr.UserId), Time.Value)
            end)
            if not success then
                warn("Failed to save data:", err)
            end
        end
        task.wait(1)
    end
    
    
end)```
brazen marten
#

did you puplish properly

spice cipher
#

maybe im going to check

#

Yes i have api access on

fair furnace
#

like resave it to roblox twin

spice cipher
#

oh

fair furnace
#

go to file and save to roblox

spice cipher
#

gng im so stupid

fair furnace
#

ur good

spice cipher
#

it worked.

#

im so sorry for wasting your time