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

How do I show Saved Data on the Leaderboard? Or if not Leaderboard, then somewhere else like a UI

Asked by 4 years ago
Edited 4 years ago

Hello! I'm fresh to scripting and followed the Saving Player Data guide over at https://developer.roblox.com/articles/Saving-Player-Data

Using this code, I also used another script inside of an object that gives gold/money when I touch it:

local PlayerStatManager = require(game.ServerStorage.PlayerStatManager)

local me = script.Parent



local function GiveMoney(part)

local hum = part.Parent:FindFirstChild("Humanoid")

local plName = part.Parent.Name

if hum then

local player = game.Players:FindFirstChild(plName)

PlayerStatManager:ChangeStat(player,"Money",2)

me:Destroy()

end

end



me.Touched:Connect(GiveMoney)

So then when I have this script inside of ServerScriptService..

local function onPlayerJoin(player)

local leaderstats = Instance.new("Folder")

leaderstats.Name = "leaderstats"

leaderstats.Parent = player

-- Display an 'IntValue' on leaderboard

local gold = Instance.new("IntValue")

gold.Name = "Gold"

gold.Value = 0

gold.Parent = leaderstats

local experience = Instance.new("IntValue")

experience.Name = "Experience"

experience.Value = 0

experience.Parent = leaderstats

end

-- Run 'onPlayerJoin()' when the 'PlayerAdded' event fires

game.Players.PlayerAdded:Connect(onPlayerJoin)

I expected that what I picked up would be updated in the leaderstats board and it wasn't. I've tried Googling and thinking about it myself but I'm at a loss. Any help would be appreciated!

1 answer

Log in to vote
0
Answered by
mc3334 649 Moderation Voter
4 years ago

From my view, it sounds like the script in server script service needs to be a module script. You can only run functions in a script from another script through a module script. You can directly communicate between two scripts.

Ad

Answer this question