:FindFirstChild() function Not Detecting Models

So, i was Actually Working on Placer Tool That Allows us to Spawn any Objects if we want!

I’m Modeling an Machine Called “Placer Changer” that Changes the Placer Tool. i Programmed it, and i Tested Out, But For Some Reason, It did not detect the Model because Script Thinks nothing was found on the folder, but it has Model in this Folder.
image

I Got Very Confused why Script not Detecting the Model on the Folder.

Here’s the Video For Example:

And Also Here’s the Script:

local Placer = game.ReplicatedStorage:WaitForChild("Placer")
local Storage = game.ReplicatedStorage.PlacerStorage

script.Parent.Frame.TextButton.MouseButton1Click:Connect(function()
	if Storage:FindFirstChild(script.Parent.Frame.NameLabel.TextBox.Text) ~= nil then
		script.Parent.Enabled = false
		script.Parent.Parent["TurnOn/Off"]:Play()
		script.Parent.Parent.Change:Play()
		Placer.Selected.Value = Storage:FindFirstChild(script.Parent.Frame.NameLabel.TextBox.Text)
		Placer.Delay.Value = script.Parent.Frame.DelayLabel.TextBox.Text
		task.wait(0.5)
		Placer.Parent = game.Workspace
		Placer:PivotTo(script.Parent.Parent.Parent.Exit.Hole.CFrame)
	else
		script.Parent.Parent.Error:Play()
	end
end)

Someone Give Me An Solution Please.

2 Likes

I suggest using WaitForChild() instead for the storage :confused:

Try waiting for PlacerStorage as well local Storage = game.ReplicatedStorage.WaitForChild("PlacerStorage")

Verify if script.Parent.Frame.NameLabel.TextBox.Text really returns the correct text using either debugging or printing.

i tried it, but it still not detects it

local Placer = game.ReplicatedStorage:WaitForChild("Placer")
local Storage = game.ReplicatedStorage:WaitForChild("PlacerStorage")

script.Parent.Frame.TextButton.MouseButton1Click:Connect(function()
	if Storage:WaitForChild(tostring(script.Parent.Frame.NameLabel.TextBox.Text)) then
		script.Parent.Enabled = false
		script.Parent.Parent["TurnOn/Off"]:Play()
		script.Parent.Parent.Change:Play()
		Placer.Selected.Value = Storage:FindFirstChild(script.Parent.Frame.NameLabel.TextBox.Text)
		Placer.Delay.Value = script.Parent.Frame.DelayLabel.TextBox.Text
		task.wait(0.5)
		Placer.Parent = game.Workspace
		Placer:PivotTo(script.Parent.Parent.Parent.Exit.Hole.CFrame)
	else
		script.Parent.Parent.Error:Play()
	end
end)

i Tested Your Solution But I Got a Warning, “Infinite yield possible on 'ReplicatedStorage.PlacerStorage:WaitForChild(”“)'”. Can You Please Fix that Up?

This may be because there is no Placer Storage existing in your Replicated Storage. Can you send a screenshot of your Replicated Storage please?

This will not work, :WaitForChild() is not meant to check if there is a part or if it is not existent.

Also @Nedas1593011, could you show us what the GUI looks like and the location of the TextBox and the location of the script inside explorer.

Here:


bandicam 2023-04-18 10-29-09-914

Also could you test this inside the MouseButton1Click connection:

local Name = script.Parent.Frame.NameLabel.TextBox.Text
local Model = Storage:FindFirstChild(Name or "")
if Model then
   print(Name .. " has been found")
   ...
   Placer.Selected.Value = Model
   ...
else
   print("Model not found: " .. Name)
   ...
end

Also let me know what gets printed when the model is not found.

Side-note, replace the ... with what you had previously in your script.

local Name = script.Parent.Frame.NameLabel.TextBox.Text
local Model = Storage:FindFirstChild(Name or "")
if Model then
   print(Model, " has been found")
   script.Parent.Enabled = false
	script.Parent.Parent["TurnOn/Off"]:Play()
	script.Parent.Parent.Change:Play()
   Placer.Selected.Value = Model
   Placer.Delay.Value = script.Parent.Frame.DelayLabel.TextBox.Text
   task.wait(0.5)
	Placer.Parent = game.Workspace
	Placer:PivotTo(script.Parent.Parent.Parent.Exit.Hole.CFrame)
else
   print("Model not found: " .. Name)
   script.Parent.Parent.Error:Play()
end

Put that inside the MouseButton1Click connection

i pressed Select Button, it prints "Model not found: ", i seems There’s the Problem for Name, idk.

Alright so the issue has to do with the script not being able to read the TextBox. This has to do with the script being server-sided, instead the script should be client-sided and then fire a RemoteEvent to the server with the name of the model. So basically you move the current connection of the server into a connection of a RemoteEvent being fired then you get a client to fire the RemoteEvent on MouseClick.

i used an RemoteEnent on Client Runs on Server, but, Nothing happens. No Errors, And No Debug Errors What So Ever.

RemoteEvent client Converts to server Did Not Work For Me.