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.

script.Parent.Main.EnterText.FocusLost:connect(function ()
    if script.Parent.Main.EnterText.Text == "[ Enter Text ]" then return end
    if script.Parent.Main.EnterText.Text == "" then return end
    plyrs = game.Players:GetPlayers()
    for i = 1, #plyrs do
        if not plyrs[i].PlayerGui:FindFirstChild("Comms") then
            if not plyrs[i].Backpack:FindFirstChild("Virgo Comm") then return end
            L = plyrs[i].Backpack:FindFirstChild("Virgo Comm")
            L.Main.Messages.MSG5.Text = L.Main.Messages.MSG4.Text
            wait()
            L.Main.Messages.MSG4.Text = L.Main.Messages.MSG3.Text
            wait()
            L.Main.Messages.MSG3.Text = L.Main.Messages.MSG2.Text
            wait()
            L.Main.Messages.MSG2.Text = L.Main.Messages.MSG1.Text
            wait()
            L.Main.Messages.MSG1.Text = ""
            wait()
            L.Main.Messages.MSG1.Text =  script.Parent.Parent.Parent.Name.."// "..game.Players:FindFirstChild(script.Parent.Parent.Parent.Name).PlayerGui.Comms.Main.EnterText.Text
            wait()
            L.Comms.Alert:Clone().Parent = L.Parent.Parent.Character.Head()
            L.Parent.Parent.Character.Head.Alert.PlayOnRemove = true
            L.Parent.Parent.Character.Head.Alert:remove()

        end
        C = plyrs[i].PlayerGui:FindFirstChild("Comms")
        C.Main.Messages.MSG5.Text = C.Main.Messages.MSG4.Text
        wait()
        C.Main.Messages.MSG4.Text = C.Main.Messages.MSG3.Text
        wait()
        C.Main.Messages.MSG3.Text = C.Main.Messages.MSG2.Text
        wait()
        C.Main.Messages.MSG2.Text = C.Main.Messages.MSG1.Text
        wait()
        C.Main.Messages.MSG1.Text = ""
        wait()
        C.Main.Messages.MSG1.Text =  script.Parent.Parent.Parent.Name.."// "..game.Players:FindFirstChild(script.Parent.Parent.Parent.Name).PlayerGui.Comms.Main.EnterText.Text
        wait()
        C.Alert:Play()
    end
    script.Parent.Main.EnterText.Text = "[ Enter Text ]"
end)

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:

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

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

local focusLostRemoteEvent = Instance.new("RemoteEvent")
focusLostRemoteEvent.Name = "FocusLostRemoteEvent"
focusLostRemoteEvent.Parent = script.Parent.Main.EnterText
focusLostRemoteEvent.OnServerEvent:connect(function()
    if script.Parent.Main.EnterText.Text == "[ Enter Text ]" then return end
    if script.Parent.Main.EnterText.Text == "" then return end
    plyrs = game.Players:GetPlayers()
    for i = 1, #plyrs do
        if not plyrs[i].PlayerGui:FindFirstChild("Comms") then
            if not plyrs[i].Backpack:FindFirstChild("Virgo Comm") then return end
            L = plyrs[i].Backpack:FindFirstChild("Virgo Comm")
            L.Main.Messages.MSG5.Text = L.Main.Messages.MSG4.Text
            wait()
            L.Main.Messages.MSG4.Text = L.Main.Messages.MSG3.Text
            wait()
            L.Main.Messages.MSG3.Text = L.Main.Messages.MSG2.Text
            wait()
            L.Main.Messages.MSG2.Text = L.Main.Messages.MSG1.Text
            wait()
            L.Main.Messages.MSG1.Text = ""
            wait()
            L.Main.Messages.MSG1.Text =  script.Parent.Parent.Parent.Name.."// "..game.Players:FindFirstChild(script.Parent.Parent.Parent.Name).PlayerGui.Comms.Main.EnterText.Text
            wait()
            L.Comms.Alert:Clone().Parent = L.Parent.Parent.Character.Head()
            L.Parent.Parent.Character.Head.Alert.PlayOnRemove = true
            L.Parent.Parent.Character.Head.Alert:remove()

        end
        C = plyrs[i].PlayerGui:FindFirstChild("Comms")
        C.Main.Messages.MSG5.Text = C.Main.Messages.MSG4.Text
        wait()
        C.Main.Messages.MSG4.Text = C.Main.Messages.MSG3.Text
        wait()
        C.Main.Messages.MSG3.Text = C.Main.Messages.MSG2.Text
        wait()
        C.Main.Messages.MSG2.Text = C.Main.Messages.MSG1.Text
        wait()
        C.Main.Messages.MSG1.Text = ""
        wait()
        C.Main.Messages.MSG1.Text =  script.Parent.Parent.Parent.Name.."// "..game.Players:FindFirstChild(script.Parent.Parent.Parent.Name).PlayerGui.Comms.Main.EnterText.Text
        wait()
        C.Alert:Play()
    end
    script.Parent.Main.EnterText.Text = "[ Enter Text ]"
end)

Doing that should fix the problem.

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

Answer this question