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)
Use
if not plrgui:FindFirstChild("MessageGui")
rather than
if plrgui:FindFirstChild("MessageGui") ~= nil and