Can't find model in replicatedstorage

  1. What am I making? I’m making a furniture placement system if you search your wanted model then you can place it, the code below i’m making is placing the model in workspace, It’s serverside

  2. What do you want to achieve? Finding the model in ReplicatedStorage

  3. What is the issue? SearchBarResults can’t find anything on ReplicatedStorage

  4. What solutions have you tried so far? No solutions at all, i’m very confused

script.Parent.PlaceModel.OnServerEvent:Connect(function()
    local Storage = game.ReplicatedStorage.Models
    local SearchBar = script.Parent.SearchBar
    local ViewModel = game.Workspace:FindFirstChild("PreviewModel")
    local SearchBarResults = Storage:FindFirstChild(SearchBar.Text)
    local ClonedModel = SearchBarResults:Clone()
    
    ClonedModel.Parent = game.Workspace
    ClonedModel:SetPrimaryPartCFrame(CFrame.new(ViewModel.Primary.Position.X, ViewModel.Primary.Position.Y, ViewModel.Primary.Position.Z))
end)

Explorer:

kjkl;lkjhv

It’s best if you give us the error that it gave you.

Players.rolesfaker.PlayerGui.ScreenGui.Script:6: attempt to index nil with ‘Clone’

I dont think you can access replicated storage from local scripts

It seems like you’re trying to clone the text, not the model. You should refer the model instead then clone it.

you cant clone the text on searchbar

This is a server script. Local scripts can also access to replicated storage.

1 Like

Do try printing out what SearchBarResults really is before you start to Clone() as I’m guessing it’s a TextBox of some sort in the Output

your editing the textbox on the client so you would need a local script to read the text

sorry for late reply, it’s still not working

tried it, it prints nil in the output

its still not working


findfirstchild(tostring(searchbar.text))

not working too oof, it just prints nil

Is SearchBar.Text modified in a LocalScript? If so, the server won’t know what that is, and you should instead pass the SearchBar.Text string through your PlaceModel event.
It also would be helpful if we could see the SearchBar.Text value and the code from the LocalScript.

1 Like

yes, the searchbar.text is modified in localscript

this is the code from localscript:

local Player = game:GetService("Players").LocalPlayer
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")

local Storage = game.ReplicatedStorage.Models
local Mouse = Player:GetMouse()
local SearchBar = script.Parent.SearchBar
local Enter = script.Parent.Enter

script.Parent.Enter.MouseButton1Click:Connect(function()
	print("Model Placement Activated")
	for i, Enter in pairs(script.Parent:GetChildren()) do
		if Enter:IsA("TextButton") then
			if Storage:FindFirstChild(SearchBar.Text) then
				local SearchBarResult = Storage:FindFirstChild(SearchBar.Text)
				local ClonedModel = SearchBarResult:Clone()
				ClonedModel.Parent = game.Workspace
				
				RunService.RenderStepped:Connect(function()
					Mouse.TargetFilter = ClonedModel
					ClonedModel:SetPrimaryPartCFrame(CFrame.new(Mouse.Hit.X, Mouse.Hit.Y, Mouse.Hit.Z))
					ClonedModel.Name = "PreviewModel"
				end)

				--R KEYS
				UIS.InputBegan:Connect(function(Input)
					if Input.KeyCode == Enum.KeyCode.R then
						local Rotate = ClonedModel.Hitbox.Orientation.Y
						local Orientation = ClonedModel.Hitbox.Orientation
						Loop = true
						print("R Pressed")
						while Loop do
							wait()
							ClonedModel.Hitbox.Orientation = Vector3.new(0, 3, 0)
						end
					end
				end)
				UIS.InputEnded:Connect(function(Input)
					if Input.KeyCode == Enum.KeyCode.R then
						Loop = false
					end
				end)

				--Q KEYS
				UIS.InputBegan:Connect(function(Input)
					if Input.KeyCode == Enum.KeyCode.Q then
						local Rotate = ClonedModel.Hitbox.Orientation.Y
						Loop2 = true
						print("Q Pressed")
						while Loop2 do
							wait()
							ClonedModel.Hitbox.Orientation = Vector3.new(0, -3, 0)
						end
					end
				end)
				UIS.InputEnded:Connect(function(Input)
					if Input.KeyCode == Enum.KeyCode.Q then
						Loop2 = false
					end
				end)

				--MOUSE KEY
				UIS.InputBegan:Connect(function(Input)
					if Input.UserInputType == Enum.UserInputType.MouseButton1 then
						print("Model Placed")
						script.Parent.PlaceModel:FireServer()
					end
				end)
			else
				
			end
		end
	end
end)

Just, pass the TextLabel.Text inside your Event and do the same thing when you connect it on the Server Script for it to work

--Local
local Player = game:GetService("Players").LocalPlayer
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")

local Storage = game.ReplicatedStorage.Models
local Mouse = Player:GetMouse()
local SearchBar = script.Parent.SearchBar
local Enter = script.Parent.Enter

script.Parent.Enter.MouseButton1Click:Connect(function()
	print("Model Placement Activated")
	for i, Enter in pairs(script.Parent:GetChildren()) do
		if Enter:IsA("TextButton") then
			if Storage:FindFirstChild(SearchBar.Text) then
				local SearchBarResult = Storage:FindFirstChild(SearchBar.Text)
				local ClonedModel = SearchBarResult:Clone()
				ClonedModel.Parent = game.Workspace
				
				RunService.RenderStepped:Connect(function()
					Mouse.TargetFilter = ClonedModel
					ClonedModel:SetPrimaryPartCFrame(CFrame.new(Mouse.Hit.X, Mouse.Hit.Y, Mouse.Hit.Z))
					ClonedModel.Name = "PreviewModel"
				end)

				--R KEYS
				UIS.InputBegan:Connect(function(Input)
					if Input.KeyCode == Enum.KeyCode.R then
						local Rotate = ClonedModel.Hitbox.Orientation.Y
						local Orientation = ClonedModel.Hitbox.Orientation
						Loop = true
						print("R Pressed")
						while Loop do
							wait()
							ClonedModel.Hitbox.Orientation = Vector3.new(0, 3, 0)
						end
					end
				end)
				UIS.InputEnded:Connect(function(Input)
					if Input.KeyCode == Enum.KeyCode.R then
						Loop = false
					end
				end)

				--Q KEYS
				UIS.InputBegan:Connect(function(Input)
					if Input.KeyCode == Enum.KeyCode.Q then
						local Rotate = ClonedModel.Hitbox.Orientation.Y
						Loop2 = true
						print("Q Pressed")
						while Loop2 do
							wait()
							ClonedModel.Hitbox.Orientation = Vector3.new(0, -3, 0)
						end
					end
				end)
				UIS.InputEnded:Connect(function(Input)
					if Input.KeyCode == Enum.KeyCode.Q then
						Loop2 = false
					end
				end)

				--MOUSE KEY
				UIS.InputBegan:Connect(function(Input)
					if Input.UserInputType == Enum.UserInputType.MouseButton1 then
						print("Model Placed")
						script.Parent.PlaceModel:FireServer(SearchBar.Text) --This will save as a parameter for when you connect the event
					end
				end)
			else
				
			end
		end
	end
end)

The server script will be the same thing, as you’ll be passing that parameter back onto the server (Also you’re messing with the StarterGUI which could be your issue as to why it’s printing out nil)

script.Parent.PlaceModel.OnServerEvent:Connect(function(player, TextResult)
    print(TextResult)
    local Storage = game.ReplicatedStorage.Models
    local ViewModel = game.Workspace:FindFirstChild("PreviewModel")
    local SearchBarResults = Storage:FindFirstChild(TextResult)
    if SearchBarResults then --You could also do a check to make sure that the result you entered is valid so it won't result in those errors
        local ClonedModel = SearchBarResults:Clone()
    
        ClonedModel.Parent = game.Workspace
 
       ClonedModel:SetPrimaryPartCFrame(CFrame.new(ViewModel.Primary.Position.X, ViewModel.Primary.Position.Y, ViewModel.Primary.Position.Z))
    end
end)
2 Likes