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

Trying to make a radio GUI, what have I done wrong?

Asked by 10 years ago

Okay, so apparently this works in studio when I solo test it, but not on an actual server. Can anyone see the error? I'm trying to make a functioning radio.

01script.Parent.Main.EnterText.FocusLost:connect(function ()
02    if script.Parent.Main.EnterText.Text == "[ Enter Text ]" then return end
03    if script.Parent.Main.EnterText.Text == "" then return end
04    plyrs = game.Players:GetPlayers()
05    for i = 1, #plyrs do
06        if not plyrs[i].PlayerGui:FindFirstChild("Comms") then
07            if not plyrs[i].Backpack:FindFirstChild("Virgo Comm") then return end
08            L = plyrs[i].Backpack:FindFirstChild("Virgo Comm")
09            L.Main.Messages.MSG5.Text = L.Main.Messages.MSG4.Text
10            wait()
11            L.Main.Messages.MSG4.Text = L.Main.Messages.MSG3.Text
12            wait()
13            L.Main.Messages.MSG3.Text = L.Main.Messages.MSG2.Text
14            wait()
15            L.Main.Messages.MSG2.Text = L.Main.Messages.MSG1.Text
View all 42 lines...

1 answer

Log in to vote
1
Answered by
noliCAIKS 210 Moderation Voter
10 years ago

Make sure you use a LocalScript when using events in GUIs! While some events do work in normal scripts, others such as FocusLost do not! The reason it worked in Solo mode but not on a server is because in Solo, normal scripts are executed locally. However, this does create another problem. You can not access another player's PlayerGui from a LocalScript. To solve this, try using a RemoteEvent.

In a LocalScript at the place where you had your script, put this:

1local focusLostRemoteEvent = script.Parent:WaitForChild("Main"):WaitForChild("EnterText"):WaitForChild("FocusLostRemoteEvent")
2script.Parent.Main.EnterText.FocusLost:connect(function()
3    focusLostRemoteEvent:FireServer()
4end)

Then, replace the code you had in your normal Script with this:

01local focusLostRemoteEvent = Instance.new("RemoteEvent")
02focusLostRemoteEvent.Name = "FocusLostRemoteEvent"
03focusLostRemoteEvent.Parent = script.Parent.Main.EnterText
04focusLostRemoteEvent.OnServerEvent:connect(function()
05    if script.Parent.Main.EnterText.Text == "[ Enter Text ]" then return end
06    if script.Parent.Main.EnterText.Text == "" then return end
07    plyrs = game.Players:GetPlayers()
08    for i = 1, #plyrs do
09        if not plyrs[i].PlayerGui:FindFirstChild("Comms") then
10            if not plyrs[i].Backpack:FindFirstChild("Virgo Comm") then return end
11            L = plyrs[i].Backpack:FindFirstChild("Virgo Comm")
12            L.Main.Messages.MSG5.Text = L.Main.Messages.MSG4.Text
13            wait()
14            L.Main.Messages.MSG4.Text = L.Main.Messages.MSG3.Text
15            wait()
View all 45 lines...

Doing that should fix the problem.

0
Thank you SO MUCH! SquirreIOnToast 309 — 10y
Ad

Answer this question