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

How to change player's IntValue depending on how many children a parent has?

Asked by
R0jym 47
1 year ago
Edited 1 year ago

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)

2 answers

Log in to vote
0
Answered by 1 year ago

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)
Ad
Log in to vote
0
Answered by
SuperPuiu 497 Moderation Voter
1 year ago

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.

Answer this question