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
What do you want to achieve? Finding the model in ReplicatedStorage
What is the issue? SearchBarResults can’t find anything on ReplicatedStorage
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)
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.
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)