Hello there, I have a script here where it's supposed to detect how many parts does a folder have and that amount of folder's parts will be the player's value in the leaderboards, however it does not work, how do I fix this?
local user = game:GetService("Players").LocalPlayer local RS = game:GetService("ReplicatedStorage") local Checker = RS:WaitForChild("CheckerEvent") local teams = game:GetService("Teams") local leaderstats = user:WaitForChild("leaderstats") local blocks = leaderstats:WaitForChild("Blocks") --------------- local red = workspace.Blocks.Red:GetChildren() local blue = workspace.Blocks.Blue:GetChildren() --------------- Checker.OnClientEvent:Connect(function(event) if user.Team == teams.Red then blocks.Value = #red else blocks.Value = #blue end end)
This should work. MAKE SURE YOU USE A NORMAL SCRIPT.
local Folder = --your folder-- local Score = nil local IntValue = --your value-- for i,v in pairs(Folder:GetChildren) do Score = v end IntValue.Value = Score print(IntValue.Value)
Not sure if you will have in your Parent
models as well, but you can use :GetChildren()
. Example:
local folder = script -- change script to where is located the folder local Children = folder:GetChildren() print(#Children)
Now, if I remember right #
at the end of the table is for getting last key. Anyway you could do a simple search on google and get your answer.