Problems when passing a value from the client to the server using remote events

Im trying to make a UI which inserts models, but for some reason, when I pass a value from the client tto the server using parameters and arguments, the value stays in the client.
LocalScript:

local textbox = script.Parent.Parent.TextBox
local event = workspace.InsertModel.ClickID
local value = workspace.InsertModel.ID

script.Parent.MouseButton1Click:Connect(function(hi)
	if textbox.Text ~= "ID" or textbox.Text ~= nil then
		value.Value = textbox.Text
		event:FireServer(tonumber(textbox.Text))
	end
end)


ServerScript:

local InsertService = game:GetService("InsertService")
local folder = script.Parent
local ID = folder.ID
local event = folder.ClickID


event.OnServerEvent:Connect(function(hi, text)
	local char = hi.Character
	local Model = InsertService:LoadAsset(text)  
	print("Value:" ..ID.Value)
		 
	Model.Parent = workspace 
	Model:MoveTo(Vector3.new(char.HumanoidRootPart.Position))
end)


Thanks in advance.

2 Likes

I don’t think there is a MoveTo() function for models, maybe try positioning?
PS: You can use breakpoints to see if it’s sending to server or not.

2 Likes

Actually there’s a MoveTo function for model.

@gpm231 can you explain more on this:

2 Likes

I already know that its not sending to the server. Im asking to see if maybe I have errors in the script that are making the value not go to the server.

1 Like

Try doing

if textbox.Text ~= "ID" or textbox.Text ~= "" then
      --Code
end
2 Likes

By the way, why did you send server the same thing and created a seperate value for ID? Also you can’t set values in a LocalScript.

3 Likes

Have you tried removing the parameter in the MouseButton1Click event? That event doesn’t have any parameters/arguments.

3 Likes

Model:MoveTo() is one way to position…

2 Likes

LoadAsset() only works on Assets You Own.
Try printing text

Also, Lua returns nil if it can’t turn the text into a number

TextBox.Text ~= nil will never be false. Since it will never be nil.

LoadAsset should also have errored

2 Likes

There’s a chance when you do tonumber() that the text contains non-numbers.

Try this.

script.Parent.MouseButton1Click:Connect(function(hi)
	if not string.match(textbox.Text, "^[%d%s]”) then
		value.Value = textbox.Text
		event:FireServer(tonumber(textbox.Text))
	end
end)

Previous reply says :LoadAsset() only works on owned assets as well but it also works for Roblox owned assets.

1 Like

HumanoidRootPart.Position is already a Vector3. You don’t need to construct a new one, and you can’t use another vector as a parameter for that constructor anyway..

Replace that line with this:

if (char ~= nil and char:FindFirstChild("HumanoidRootPart") ~= nil) then
	Model:MoveTo(char.HumanoidRootPart.Position)
end
1 Like

I think that is what fixed it. Could you explain to me what that does? Thank you.

I made a minor mistake and edited it but basically I look for any non-number and non-whitespace characters then execute the code if so.

You could also remove the non-numbers with string.gsub:

local result = string.gsub(text, “^[%d])
if string.match(result, “%d”) then — could still be nothing left
    result = tonumber(result)
    — code
end

%d looks for digits
%s looks for whitespace
^ looks for the opposite of the patterns
[] is just needed for sets in patterns
^[%d%s] all non-digit non-whitespace characters

1 Like