#need help on leaderboard

43 messages · Page 1 of 1 (latest)

obsidian trench
#

I was watching a tutorial and I did everything the same, but dust and coins don't appear on the leaderboard when I play

blissful mural
#

make sure it's in a server script and inside ServerScriptService or somewhere else that also works

obsidian trench
#

local Players = game:GetService("players")

local function givePlayerCurrency(player: Player)

local function setupPlayerData(player: Player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
SW
local dust = Instance.new("IntValue", leaderstats)
dust.Name = "Dust"
dust.Value = 0

local coins = Instance.new("IntValue", leaderstats)
coins.Name = "Coins"
coins.Value = 0

end

Players.PlayerAdded:Connect(setupPlayerData)

obsidian trench
blissful mural
#

you never ended your first function

#

you defined it but never gave it an end

#

another thing that should be changed is this

#

defining the parent in the same line isnt efficient

#

i'll give you a working script to look over

#
game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    
    local dust = Instance.new("IntValue")
    dust.Name = "Dust"
    dust.Value = 0
    dust.Parent = leaderstats

    local coins = Instance.new("IntValue")
    coins.Name = "Coins"
    coins.Value = 0
    coins.Parent = leaderstats
end)
#

let me know if that works

obsidian trench
#

ty

#

ill look your script

blissful mural
obsidian trench
#

it worked!

vast jacinthBOT
#

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

obsidian trench
#

ty so much

blissful mural
#

np

sharp turret
blissful mural
#

something about having to replicate it to each client individually

#

one min

#

This video will teach you how to insert objects via a script by using the Instance.new() function, and also why using the second parent argument of the function is a bad idea.

Join membership for EXCLUSIVE perks:
https://www.youtube.com/channel/UCp1R0TBvgM7gj0rwTYULmSA/join

SUBSCRIBE to learn how to master Roblox scripting:
https://www.youtube...

▶ Play video
#

been a thing for a while and it's always been recommended to not do that because it's not efficient

sharp turret
#

he said it's bad for running the code as it is not optimized, i really don't know what's better, i will search it later

#

👍

blissful mural
# sharp turret he said it's bad for running the code as it is not optimized, i really don't kno...
#

read up on this

#

it's much less performance heavy to define the parent afterwards

#

for that same reason, the parent should also be defined last in your Instance.new

sharp turret
#

basically roblox changes the parent first than all the other things that are more important

blissful mural
#

in simple terms, when you do Instance.new it's less performance heavy because the instance isnt spawned into the game yet and it's not loaded, which means changes aren't being observed by either the server or client

sharp turret
#

that?

blissful mural
#

In ROBLOX, objects start as detached from the game object and are left in this state up until you parent them to something that’s already a descendant of game. When the object is detached (meaning, .Parent = nil or maybe object is parented to some other object that is not parented to anything), changing the state of the object is very cheap - you’re just changing bytes inside some memory block.

blissful mural
#

it's just less performance heavy to change the properties of the instance before it's loaded

#

read on the devforum post i sent, he covers everything about it

sharp turret
#

oh, so basically u will make a part for example with all the default properties then u will change it, while u could just set the properties and change the parent

vast jacinthBOT
#

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