Basically i want to check every Value whithin the children inside the “vals” folder:
I’ve tried using GetChildren in two ways (with and without a for loop) but it doesn’t seem i am figuring out how to do it properly.
This is the script till the Children checking:
local DataStore2 = require(game:GetService("ServerScriptService").DataStore2)
local checkerFlag = script.Parent.Parent.CheckerFlag
local vals = game.ReplicatedStorage.vals
local allVals = vals:GetChildren()
local mainVal = vals.Winner
local mainID = mainVal.WinnerID
local Part1 = script.Parent
local Part2 = script.Parent.Parent.SecondPart
local ingameQuantity = game.Workspace.GameScripts.Main.PlayerQuantity
local DEFAULT_DATA = {
Stats = {
["Gold"] = 0,
["Silver"] = 0,
["Bronze"] = 0,
["Rushies"] = 0,
["Level"] = 1,
["Exp"] = 0,
["MaxExp"] = 100,
["ExtraExp"] = 0,
["AllExp"] = 0,
}
}
script.Parent.Touched:Connect(function(hit)
local vals = game.ReplicatedStorage.vals
local h = hit.Parent:FindFirstChild("Humanoid")
local BaseXP = 17
local BaseRushies = 15
local GainXP = BaseXP * ingameQuantity.Value
local GainRushies = BaseRushies * ingameQuantity.Value
if (h~=nil) then
for i = 1, #allVals do
if mainVal.Value == "" and hit.Parent.Name ~= allVals[i].Value then
I think i may have explained wrong, i don’t want to check Children inside children, i want to check the Value inside the every Children (StringValues):
Also, i tried your method but i don’t think i got it right, it was supposed to be that way:
for _, child in ipairs(vals:GetChildren()) do
if mainVal.Value == “” and hit.Parent.Name ~= child.Value then
Cause i am getting nothing on the output.
What this is script does is check if mainVal.Value is nil and if the name of the player is different to all the Children values.
That’s basically what i was searching for, but yet, i am not being able to check the Values inside every children, i tried to print it and it keeps returning nothing:
What my script looks like:
for i, v in pairs(vals:GetChildren()) do
if mainVal.Value == "" and hit.Parent.Name ~= v.Value then
print(v.Value)
and hit.Parent.Name ~= v.Value
This piece of code is meant to check all the String Values inside the Children, and if any of these values is = the Name of the player who touched the part, the rest of the code won’t proceed, but the problem is i am failing to verify the Values even with the for loops, i don’t get what i am doing wrong
I don’t know if you can, but, what I do in such situations is, I start by searching hardcoded values. Like,
...Rest of code...
if v.Value == "Test" then
print("HEY")
end
If this, the most basic form of the code doesn’t work, there’s a problem with the rest of ur code. If there’s no error and it does exactly what u intend it to do, build the code from there upto where it’s supposed to be.
if h ~= nil then
for _, child in pairs(game.ReplicatedStorage.vals:GetChildren()) do
if mainVal.Value == "" and hit.Parent.Name ~= child.Value then
print(child.Value)
end
end
end
The code is working fine, no errors at all, the problem as i said in some comments above is, the v.Value is returning absolutely nothing, no Values at all:
The idea i am trying to achieve is, whenever a player touches the part it will check if the player who touched already has his name in one of the 12 Values (The first print of this post) and if the current value that he is being assigned is not taken then the script will proceed with it’s code:
But since the v.Value is always returning nil, the script will always proceed, i originally had this working checking every single 12 values with and’s but i wanted to use less code.
I know the error in this method is related to logic, but i am not getting how i can do this properly