Hello, I'm having some problems with TextBox. I'm making a teleport weapon using XYZ, you basically type into the TextBox the coordinates where you want to go. I think the problem is happening because the TextBox text is only changing on the client.
Here is the scripts:
Client:
local tool = script.Parent local player = game.Players.LocalPlayer tool.Equipped:Connect(function() player.PlayerGui.Vector.TextBox1.Visible = true player.PlayerGui.Vector.TextBox2.Visible = true player.PlayerGui.Vector.TextBox3.Visible = true end) tool.Unequipped:Connect(function() player.PlayerGui.Vector.TextBox1.Visible = false player.PlayerGui.Vector.TextBox2.Visible = false player.PlayerGui.Vector.TextBox3.Visible = false end) tool.Activated:Connect(function() script.Parent.TeleportEvent:FireServer(player) end)
Server:
script.Parent.TeleportEvent.OnServerEvent:Connect(function(player) player.Character.HumanoidRootPart.Position = Vector3.new(player.PlayerGui.Vector.TextBox1.Text, player.PlayerGui.Vector.TextBox2.Text, player.PlayerGui.Vector.TextBox3.Text) end)
By the way there are 3 TextBox. The first represents X, the second represents Y and the third represents Z.
local tool = script.Parent local player = game.Players.LocalPlayer local VectorHolders = player.PlayerGui.Vector --first off make a var for your vectorboxes tool.Equipped:Connect(function() VectorHolders .TextBox1.Visible = true VectorHolders .TextBox2.Visible = true VectorHolders .TextBox3.Visible = true end) tool.Unequipped:Connect(function() VectorHolders .TextBox1.Visible = false VectorHolders .TextBox2.Visible = false VectorHolders .TextBox3.Visible = false end) tool.Activated:Connect(function() local newVector = { X = VectorHolders.Text; Y = VectorHolders.Text; Z = VectorHolders.Text; } script.Parent.TeleportEvent:FireServer(player, newVector ) --fire the vector to the server end)
Replying, because @BonesIsUseless answer is incomplete.
Local script:
local tool = script.Parent --local player = game.Players.LocalPlayer -- unnecessary local VectorHolders = player.PlayerGui.Vector --first off make a var for your vectorboxes tool.Equipped:Connect(function() VectorHolders.TextBox1.Visible = true VectorHolders.TextBox2.Visible = true VectorHolders.TextBox3.Visible = true end) tool.Unequipped:Connect(function() VectorHolders.TextBox1.Visible = false VectorHolders.TextBox2.Visible = false VectorHolders.TextBox3.Visible = false end) tool.Activated:Connect(function() local newVector = { X = VectorHolders.Text; Y = VectorHolders.Text; Z = VectorHolders.Text; } script.Parent.TeleportEvent:FireServer(newVector) --fire the vector to the server -- there is no need to provide player, as this will be added automatically end)
Missing Server script:
script.Parent.TeleportEvent.OnServerEvent:Connect(function(player, newVector) -- it is always better to use CFrame for teleportation needs player.Character.HumanoidRootPart.CFrame = CFrame.new(tonumber(newVector.X), tonumber(newVector.Y), tonumber(newVector.Z)) end)