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

I made an line of code, but instead the error though I was finding the Object! [?]

I made an script that the LocalScript goes to the player before it returns. And then an error said that LocalScript is not an valid member of TextButton But I wasn't using any if and then statements? Code: (I removed the locals because I am lazy to put them on. player as game.Players.LocalPlayer)

script.Parent.Parent.Blast.LocalScript.Parent =player

							script.Parent.Parent.Transport.LocalScript.Parent = player
							script.Parent.Parent.Bullet.LocalScript.Parent = player

							script.Parent.Parent.Requiem.LocalScript.Parent = player
wait(1)
script.Parent.Parent.Blast.LocalScript.Parent = script.Parent.Parent.Blast

							script.Parent.Parent.Transport.LocalScript.Parent = script.Parent.Parent.Transport
							script.Parent.Parent.Bullet.LocalScript.Parent = script.Parent.Parent.Bullet

							script.Parent.Parent.Requiem.LocalScript.Parent = script.Parent.Parent.Requiem

And then I did not put any if and then statements but the code though I was finding the Parent, but I was going to a Parent. Any helps?

2 comments

0

you dont have to be using if statements to encounter an error

0

I mean it has no statements, but it just say the error.

1 answer

My assumption is that you only have one LocalScript in each TextButton, so when you try to change the parents of these scripts a second time, you can't since they are now under the LocalPlayer

You should also use the :WaitForChild() function to make sure the scripts even exist before running your code.

Not sure why you want to move the scripts to the player and back, but here is the revision

Revised Local Script

local player = game:GetService("Players")
local blast = script.Parent.Parent:WaitForChild("Blast")
local transport = script.Parent.Parent:WaitForChild("Transport")
local bullet = script.Parent.Parent:WaitForChild("Bullet")
local requiem = script.Parent.Parent:WaitForChild("Requiem")

local script1 = blast:WaitForChild("LocalScript")
local script2 = transport:WaitForChild("LocalScript")
local script3 = bullet:WaitForChild("LocalScript")
local script4 = requiem:WaitForChild("LocalScript")

script1.Parent = player
script2.Parent = player
script3.Parent = player
script4.Parent = player
wait(1)
script1.Parent = blast
script2.Parent = transport
script3.Parent = bullet
script4.Parent = requiem

Since the script1, script2, script3, and script4 are all predefined, changing their parent will not prevent you from using them later in the code again.

If a warning prints (infinite yield possible) then your parenting is probably wrong

1 comment

0

infinite yield possible is not an error lmao

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