Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make this Event Receiver script more efficient?

I've made a script that consists solely of multiple Remote Event receivers (in the format listed below) which will change the text of a standard GUI it creates depending on which event occurs. As you can see the script is very clunky, especially considering that it is repeated 6 times for slightly different messages so I was wondering if there was any way I can make it more efficient while ensuring that every remote event it receives has it's own unique message and only 1 message appears at a time?

I really don't know where to start. All help is appreciated!

local plr = game.Players.LocalPlayer
local gui = game.ReplicatedStorage.MessageGui
local plrgui = plr.PlayerGui

-- Everything below is repeated 6 times in the same script

game.ReplicatedStorage.OwnsTycoonGui.OnClientEvent:Connect(function()
    if plrgui:FindFirstChild("MessageGui") ~= nil and plrgui:FindFirstChild("MessageGui").Message.Text ~= "1" then -- 1 = message number
        print(plr.Name)
        plr.PlayerGui.MessageGui.Message.Text = "1"
        plr.PlayerGui.MessageGui.Message.Alert.Text = "Message"
    end
    if plrgui:FindFirstChild("MessageGui") == nil then
        gui:Clone().Parent = plr.PlayerGui
        plr.PlayerGui.MessageGui.Message.Text = "1"
        plr.PlayerGui.MessageGui.Message.Alert.Text = "Same message as above"
    end
    wait(3)
    if plrgui:FindFirstChild("MessageGui") ~= nil and plrgui:FindFirstChild("MessageGui").Message.Text == "1" then
        plr.PlayerGui.MessageGui:Destroy()
    end
end)

1 comment

0

1 answer

Use

if not plrgui:FindFirstChild("MessageGui")

rather than

if plrgui:FindFirstChild("MessageGui") ~= nil and

1 comment

0

Isn't fixing the problem, but I would use the former over the latter.

This discussion is preserved as it was. New answers, comments, and votes are closed.