#Gui & Leadertstats/Data are not in sync

1 messages · Page 1 of 1 (latest)

keen kraken
#

these are all the scripts i am using

#

Template:

    Clicks = 0,
    Yens = 0,
    Gems = 0
}```
#

Manager:


local Remotes = ReplicatedStorage:WaitForChild("Remotes")

local Manager = {}

Manager.Profiles = {}

function Manager.AdjustClicks(player: Player, amount: number)
    local profile = Manager.Profiles[player]
    if not profile then return end

    -- Initialize clicks if nil and add amount
    profile.Data.Clicks = (profile.Data.Clicks or 0) + amount

    -- Update leaderstats
    if player:FindFirstChild("leaderstats") then
        player.leaderstats.Clicks.Value = profile.Data.Clicks
    end

    -- Update client GUI
    local updateRemote = Remotes:FindFirstChild("UpdateClicks")
    if updateRemote then
        updateRemote:FireClient(player, profile.Data.Clicks)
    end
end

return Manager```
#

does let me share the data script

#

*doesnt

#

Script - Click:

local ServerScriptService = game:GetService("ServerScriptService")

local Remotes = ReplicatedStorage.Remotes
local PlayerData = require(ServerScriptService.PlayerData.Manager)

local Cooldown = {}
local CLICK_COOLDOWN = 0.5

local function Click(player: Player)
    -- Check if player is in cooldown
    if table.find(Cooldown, player) then
        return
    end

    -- Add player to cooldown
    table.insert(Cooldown, player)

    -- Set up cooldown removal
    task.delay(CLICK_COOLDOWN, function()
        local index = table.find(Cooldown, player)
        if index then
            table.remove(Cooldown, index)
        end
    end)

    -- Process the click
    PlayerData.AdjustClicks(player, 1)
end

Remotes.Click.OnServerEvent:Connect(Click)```
#

Local Script - Manager:

local Remotes = ReplicatedStorage:WaitForChild("Remotes")

local Gui = script.Parent
local Frame = Gui:WaitForChild("Frame")

local Clicks = Frame.Clicks.Amount
local Gems = Frame.Gems.Amount

local function UpdateCurrency(currency: "Clicks" | "Gems", amount: number)
    if currency == "Clicks" then
        Clicks.Text = tostring(amount)
    elseif currency == "Gems" then
        Gems.Text = tostring(amount)
    end
end

Remotes:WaitForChild("UpdateClicks").OnClientEvent:Connect(function(amount)
    UpdateCurrency("Clicks", amount)
end)

Remotes:WaitForChild("UpdateGems").OnClientEvent:Connect(function(amount)
    UpdateCurrency("Gems", amount)
end)
amber tulipBOT
#

studio** You are now Level 1! **studio

twin igloo
#

hmm the scripts are all over the place we cant figure it out properly

#

and idk where are u storing the data but please dont do it locally store everything in the server

thorn sand
#

@keen kraken

#

I can easily fix js make it less messy

amber tulipBOT
#

studio** You are now Level 1! **studio

keen kraken
thorn sand
#

Give me a sec

#

Add this to the bottom of your AdjustClicks: function Manager.SetupProfile(player: Player)
Manager.Profiles[player] = {
Data = {
Clicks = 0,
Yens = 0,
Gems = 0
}
}

-- Setup leaderstats
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = player

local clicks = Instance.new("IntValue")
clicks.Name = "Clicks"
clicks.Value = 0
clicks.Parent = stats

-- Sync initial GUI
local updateRemote = Remotes:FindFirstChild("UpdateClicks")
if updateRemote then
    updateRemote:FireClient(player, 0)
end

end

#

ServerScript: local PlayerData = require(ServerScriptService.PlayerData.Manager)

game.Players.PlayerAdded:Connect(function(player)
PlayerData.SetupProfile(player)
end)

game.Players.PlayerRemoving:Connect(function(player)
PlayerData.Profiles[player] = nil
end)

#

add new RemoteFunction: GetPlayerData

#

That’s optional above

#

LocalScript GUI Manager: local data = Remotes:WaitForChild("GetPlayerData"):InvokeServer()
UpdateCurrency("Clicks", data.Clicks or 0)
UpdateCurrency("Gems", data.Gems or 0)

#

Server side:

Remotes.GetPlayerData.OnServerInvoke = function(player)
local profile = Manager.Profiles[player]
if profile then
return profile.Data
end
return { Clicks = 0, Gems = 0, Yens = 0 }
end

#

Check should work now

little jetty
#

and it will work?

keen kraken
#

it still doesnt work

thorn sand
#

Did u use the scripts I js sent

keen kraken
thorn sand
thorn sand
keen kraken
little jetty
keen kraken
#

i am doing "How to Create a Point System for a Simulator! How to Make a Simulator in Roblox Episode 3 - MonzterDev"

keen kraken
#

thanks for the help @little jetty @thorn sand

thorn sand
#

If u restart try to use the scripts I sent

little jetty
#

also following tutorials like that isnt a great idea

keen kraken
#

i dont know coding tho

keen kraken
little jetty
#

copying a game line for line and not actually learning is not a good idea xd