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)
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.
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.
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
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