Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

7 comments

0

Judging by the code shown, I'm assuming that the "Percent" variable is a NumberValue object, right?

0

yes

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:

1

replace Percentage with Percentage.Value on lines: 33, 26, 19, 12, 5

0

and use elseif

0

OMG I REALLY FORGOT .value, OMGGGGGG that makes me so angry, thanks for pointing that out though

0

ok still didnt work but im going to post the script at its current state

2 answers

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

3 comments

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)

0

didn't work is not an answer!!! you must show the errors in the output!!!

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.