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

Script Not Parenting Models to ReplicatedStorage with :FindFirstChild()?

Asked by 1 year ago

hi, im making a script where a number's going down (already done that script) and this script is supposed to check what the number is, and change the parents of some models depending on how big the number is, but it isnt working, can anyone help me?

local RepStorage = game.ReplicatedStorage.BoxTypes
local Percent = script.Parent.Percentage

while true do
    if Percent > 90 then
        script.Parent:FindFirstChild("Danger").Parent = RepStorage
        script.Parent:FindFirstChild("Open").Parent = RepStorage
        script.Parent:FindFirstChild("Opening").Parent = RepStorage
        script.Parent:FindFirstChild("Peeking").Parent = RepStorage
        RepStorage.Closed.Parent = script.Parent
    end
    if Percent < 90 and Percent > 65 then
        script.Parent:FindFirstChild("Danger").Parent = RepStorage
        script.Parent:FindFirstChild("Open").Parent = RepStorage
        script.Parent:FindFirstChild("Opening").Parent = RepStorage
        script.Parent:FindFirstChild("Closed").Parent = RepStorage
        RepStorage.Peeking.Parent = script.Parent
    end
    if Percent < 65 and Percent > 35 then
        script.Parent:FindFirstChild("Danger").Parent = RepStorage
        script.Parent:FindFirstChild("Open").Parent = RepStorage
        script.Parent:FindFirstChild("Closed").Parent = RepStorage
        script.Parent:FindFirstChild("Peeking").Parent = RepStorage
        RepStorage.Opening.Parent = script.Parent
    end
    if Percent < 35 and Percent > 10 then
        script.Parent:FindFirstChild("Danger").Parent = RepStorage
        script.Parent:FindFirstChild("Opening").Parent = RepStorage
        script.Parent:FindFirstChild("Closed").Parent = RepStorage
        script.Parent:FindFirstChild("Peeking").Parent = RepStorage
        RepStorage.Open.Parent = script.Parent
    end
    if Percent <= 10 then
        script.Parent:FindFirstChild("Open").Parent = RepStorage
        script.Parent:FindFirstChild("Opening").Parent = RepStorage
        script.Parent:FindFirstChild("Closed").Parent = RepStorage
        script.Parent:FindFirstChild("Peeking").Parent = RepStorage
        RepStorage.Danger.Parent = script.Parent
    end
end
0
Judging by the code shown, I'm assuming that the "Percent" variable is a NumberValue object, right? SpiritualSonicdash 67 — 1y
0
yes JmoneyPlayzOfficial 49 — 1y
1
you probably get error attempt to compare NumberValue with number, you need to compare values of same type, NumberValue is not same as number, however, you can type Percentage.Value which is a number, in other words: imKirda 4491 — 1y
1
replace Percentage with Percentage.Value on lines: 33, 26, 19, 12, 5 imKirda 4491 — 1y
View all comments (3 more)
0
and use elseif T3_MasterGamer 2189 — 1y
0
OMG I REALLY FORGOT .value, OMGGGGGG that makes me so angry, thanks for pointing that out though JmoneyPlayzOfficial 49 — 1y
0
ok still didnt work but im going to post the script at its current state JmoneyPlayzOfficial 49 — 1y

2 answers

Log in to vote
1
Answered by
imKirda 4491 Moderation Voter Community Moderator
1 year ago

oh yeah blind blind, after you parent something to ReplicatedStorage, it will be in ReplicatedStorage, not in script.Parent, you can, however, put the instances into variables, there they are going to always be accesible no matter where they are:

local RepStorage = game.ReplicatedStorage.BoxTypes
local Percent = script.Parent.Percentage

local Danger = script.Parent:FindFirstChild("Danger")
local Open = script.Parent:FindFirstChild("Open")
local Opening = script.Parent:FindFirstChild("Opening")
local Peeking = script.Parent:FindFirstChild("Peeking")

while true do
    if Percent.Value > 90 then
        Danger.Parent = RepStorage
        Open.Parent = RepStorage
        Opening.Parent = RepStorage
        Peeking.Parent = RepStorage
        Closed.Parent = script.Parent
    elseif Percent.Value < 90 and Percent.Value > 65 then
        Danger.Parent = RepStorage
        Open.Parent = RepStorage
        Opening.Parent = RepStorage
        Peeking.Parent = RepStorage
        Peeking.Parent = script.Parent
    elseif Percent.Value < 65 and Percent.Value > 35 then
        Danger.Parent = RepStorage
        Open.Parent = RepStorage
        Opening.Parent = RepStorage
        Peeking.Parent = RepStorage
        Opening.Parent = script.Parent
    elseif Percent.Value < 35 and Percent.Value > 10 then
        Danger.Parent = RepStorage
        Open.Parent = RepStorage
        Opening.Parent = RepStorage
        Peeking.Parent = RepStorage
        Open.Parent = script.Parent
    elseif Percent.Value <= 10 then
        Danger.Parent = RepStorage
        Open.Parent = RepStorage
        Opening.Parent = RepStorage
        Peeking.Parent = RepStorage
        Danger.Parent = script.Parent
    end
end

0
it didnt work, i added a closed variable and fixed some stuff like the double variable .parent things changing the parents of the same thing (i cant explain stuff) JmoneyPlayzOfficial 49 — 1y
0
didn't work is not an answer!!! you must show the errors in the output!!! imKirda 4491 — 1y
0
before the game starts, are all the Danger, Open, Opening and Peeking values in the ReplicatedStorage? you can show me your current script with your fixes if you want imKirda 4491 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

ok still hasnt worked but here is the updated script

local RepStorage = game.ReplicatedStorage.BoxTypes
local Percent = script.Parent.Percentage

while true do
    if Percent.Value > 90 then
        script.Parent:FindFirstChild("Danger").Parent = RepStorage
        script.Parent:FindFirstChild("Open").Parent = RepStorage
        script.Parent:FindFirstChild("Opening").Parent = RepStorage
        script.Parent:FindFirstChild("Peeking").Parent = RepStorage
        RepStorage.Closed.Parent = script.Parent
    elseif Percent.Value < 90 and Percent.Value > 65 then
        script.Parent:FindFirstChild("Danger").Parent = RepStorage
        script.Parent:FindFirstChild("Open").Parent = RepStorage
        script.Parent:FindFirstChild("Opening").Parent = RepStorage
        script.Parent:FindFirstChild("Closed").Parent = RepStorage
        RepStorage.Peeking.Parent = script.Parent
    elseif Percent.Value < 65 and Percent.Value > 35 then
        script.Parent:FindFirstChild("Danger").Parent = RepStorage
        script.Parent:FindFirstChild("Open").Parent = RepStorage
        script.Parent:FindFirstChild("Closed").Parent = RepStorage
        script.Parent:FindFirstChild("Peeking").Parent = RepStorage
        RepStorage.Opening.Parent = script.Parent
    elseif Percent.Value < 35 and Percent.Value > 10 then
        script.Parent:FindFirstChild("Danger").Parent = RepStorage
        script.Parent:FindFirstChild("Opening").Parent = RepStorage
        script.Parent:FindFirstChild("Closed").Parent = RepStorage
        script.Parent:FindFirstChild("Peeking").Parent = RepStorage
        RepStorage.Open.Parent = script.Parent
    elseif Percent.Value <= 10 then
        script.Parent:FindFirstChild("Open").Parent = RepStorage
        script.Parent:FindFirstChild("Opening").Parent = RepStorage
        script.Parent:FindFirstChild("Closed").Parent = RepStorage
        script.Parent:FindFirstChild("Peeking").Parent = RepStorage
        RepStorage.Danger.Parent = script.Parent
    end
end

Answer this question