#need help on leaderboard
43 messages · Page 1 of 1 (latest)
can you send your script so we can look at it
make sure it's in a server script and inside ServerScriptService or somewhere else that also works
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)
the script is in serverscriptservice
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
np, let me know if it works
it worked!
** You are now Level 1! **
ty so much
np
Why it's not efficient ?
forgot the exact reason but i remember hearing about it while learning Instance.new and i've heard other people say the same too
something about having to replicate it to each client individually
one min
https://www.youtube.com/watch?v=NM297KOSvoE
he covers it around 3:26
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...
been a thing for a while and it's always been recommended to not do that because it's not efficient
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
👍
I’ve discovered a pretty bad performance issue in one of top games that has to do with Instance.new and wanted to write about this, since this is not obvious unless you know the system inside out. Tthere are several ways to create a ROBLOX object in Lua: local obj = Instance.new(‘type’); fill obj fields local obj = Instance.new(‘type’, parent...
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
basically roblox changes the parent first than all the other things that are more important
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
that?
pretty sure that's the reason
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.
this
?
not really
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
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
** You are now Level 1! **