Hey, I have this script that prompts staff members to execute the command ‘:open (Gatenumber) (Flight No).’ Initially, everything works perfectly fine, and the designated frame becomes visible as intended. However, when the command is executed for the second time, the frame fails to appear, remaining invisible. textLabel.Parent is the Frame.
Server Sided script
local remote = game.ReplicatedStorage.UIRemotes.teleportPlayer
local group = 32753307
local rank = 1
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(Message)
if plr:GetRankInGroup(group) >= rank then
if string.lower(string.sub(Message, 1, 5)) == ":open" then
local gateNumber, flightNo = string.match(Message, ":open (%S+)%s+(%S+)")
if gateNumber and flightNo then
remote:FireClient(plr, gateNumber)
for _, player in pairs(game.Players:GetChildren()) do
local ScreenUI = player.PlayerGui:WaitForChild("ScreenGui")
local textLabel = ScreenUI.InteractableInformation.Message
textLabel.Parent.Visible = true
textLabel.Parent.TP.Text = "Teleport to Gate "..gateNumber
textLabel.Text = "Flight "..flightNo.." is now ready for boarding at gate "..gateNumber..",\nPlease make your way there."
end
end
end
end
end)
end)
Client Sided script
local player = game.Players.LocalPlayer
local ScreenUI = player.PlayerGui:FindFirstChild("ScreenGui")
local teleportUI = ScreenUI.InteractableInformation.TP
local folder = workspace.GateParts
local remote = game.ReplicatedStorage.UIRemotes.teleportPlayer
local group = nil
remote.OnClientEvent:Connect(function(gateNumber)
print(gateNumber)
if not teleportUI.Visible then
teleportUI.Visible = true
end
if gateNumber then
local gatePart = folder:FindFirstChild(gateNumber)
if gatePart and gatePart:IsA("BasePart") then
local gatePosition = gatePart.Position
teleportUI.MouseButton1Click:Connect(function()
if teleportUI.Parent.Visible then
teleportUI.Parent.Visible = false
end
player.Character:MoveTo(gatePosition)
end)
end
end
end)
It seems like the issue is related to the visibility of the teleport UI not updating correctly when the command is executed multiple times. This can be caused by the fact that the visibility is set to true in the server script, but it might not be updated correctly in the client script.
You can modify the code to ensure that the visibility of the teleport UI is handled correctly on the client side. Here’s the updated client script:
> Client-Sided Script:
local player = game.Players.LocalPlayer
local ScreenUI = player.PlayerGui:FindFirstChild("ScreenGui")
local teleportUI = ScreenUI.InteractableInformation.TP
local folder = workspace.GateParts
local remote = game.ReplicatedStorage.UIRemotes.teleportPlayer
local group = nil
-- Set initial visibility to false
teleportUI.Parent.Visible = false
remote.OnClientEvent:Connect(function(gateNumber)
print(gateNumber)
if gateNumber then
local gatePart = folder:FindFirstChild(gateNumber)
if gatePart and gatePart:IsA("BasePart") then
local gatePosition = gatePart.Position
-- Set the teleport UI text and show it
teleportUI.Text = "Teleport to Gate " .. gateNumber
teleportUI.Parent.Visible = true
teleportUI.MouseButton1Click:Connect(function()
-- Hide the teleport UI when clicked
teleportUI.Parent.Visible = false
player.Character:MoveTo(gatePosition)
end)
end
end
end)
The teleport UI visibility should now update correctly each time the command is executed.
Hope this helps and, good luck with the rest of your game!
In your server script, you should avoid changing a player’s UI on the server. Instead of changing every player’s UI on the server, you can use a remote event and use the :FireAllClients() function. From there, you can receive the event on the client and change the player’s UI there. In the code, define displayMessageRemote as a new remote event.
-- Server script
local remote = game.ReplicatedStorage.UIRemotes.teleportPlayer
local displayMessageRemote = -- define the new remote event that will fire to all clients
local group = 32753307
local rank = 1
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(Message)
if plr:GetRankInGroup(group) >= rank then
if string.lower(string.sub(Message, 1, 5)) == ":open" then
local gateNumber, flightNo = string.match(Message, ":open (%S+)%s+(%S+)")
if gateNumber and flightNo then
remote:FireClient(plr, gateNumber)
displayMessageRemote:FireAllClients(gateNumber, flightNo)
--for _, player in pairs(game.Players:GetChildren()) do
-- local ScreenUI = player.PlayerGui:WaitForChild("ScreenGui")
-- local textLabel = ScreenUI.InteractableInformation.Message
-- textLabel.Parent.Visible = true
-- textLabel.Parent.TP.Text = "Teleport to Gate "..gateNumber
-- textLabel.Text = "Flight "..flightNo.." is now ready for boarding at gate "..gateNumber..",\nPlease make your way there."
--end
end
end
end
end)
end)
-- Local script
local player = game.Players.LocalPlayer
local ScreenUI = player.PlayerGui:FindFirstChild("ScreenGui")
local teleportUI = ScreenUI.InteractableInformation.TP
local folder = workspace.GateParts
local remote = game.ReplicatedStorage.UIRemotes.teleportPlayer
local displayMessageRemote = -- define the new remote event
local group = nil
remote.OnClientEvent:Connect(function(gateNumber)
print(gateNumber)
if not teleportUI.Visible then
teleportUI.Visible = true
end
if gateNumber then
local gatePart = folder:FindFirstChild(gateNumber)
if gatePart and gatePart:IsA("BasePart") then
local gatePosition = gatePart.Position
teleportUI.MouseButton1Click:Connect(function()
if teleportUI.Parent.Visible then
teleportUI.Parent.Visible = false
end
player.Character:MoveTo(gatePosition)
end)
end
end
end)
displayMessageRemote.OnClientEvent:Connect(function(gateNumber, flightNo)
local ScreenUI = player.PlayerGui:WaitForChild("ScreenGui")
local textLabel = ScreenUI.InteractableInformation.Message
textLabel.Parent.Visible = true
textLabel.Parent.TP.Text = "Teleport to Gate "..gateNumber
textLabel.Text = "Flight "..flightNo.." is now ready for boarding at gate "..gateNumber..",\nPlease make your way there."
end)