Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

TextBox's text changing in the client only?

Asked by 2 years ago

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.

2 answers

Log in to vote
0
Answered by 2 years ago
Edited by Shawnyg 2 years ago
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)
0
sorry i didn't know how to turn that into code BonesIsUseless 0 — 2y
0
Did it for you. It's the Lua icon that is a code block Shawnyg 4330 — 2y
Ad
Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
2 years ago

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)

Answer this question