How do i enable a gui for everyone in a server?

Hello, so i got this script right here:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Str)
		if (string.sub(Str, 1, 6) == "!tweet") then 
			local Msg = string.sub(Str, 8, string.len(Str))
			Player.PlayerGui.NotificationGui.Enabled = true
			Player.PlayerGui.NotificationGui.TextLabel.Text = Msg
			Player.PlayerGui.NotificationGui.PlayerName.Text = Player.Name .. " Tweeted:"
			wait(5)
			Player.PlayerGui.NotificationGui.Enabled = false
		end
	end)
end)

and as you can see its basically making a gui visible that has the players name and what he said in the gui, the problem is that i don’t know how to enable the gui for everyone, it only gets enabled for the player that said it, can yall help?

1 Like

Well there are two ways that could work.

One way is to use remote events like this:

server:

local remoteEvent = --your remote here..
local players = game.Players

players.PlayerAdded:Connect(function(plr)
  plr.Chatted:Connect(function(msg)
     if msg:sub(1,6) ~= "!tweet" then return end

    local Message = msg:sub(8,string.len(msg))
    remoteEvent:FireAllClients(Message,plr.Name)
  end)
end)

and then in the client:

local remoteEvent = --your remote event..
local player = game.Players.LocalPlayer
local UI = player.PlayerGui.NotificationGui

remoteEvent.OnClientEvent:Connect(function(Message : string,Name : string)
    UI.Enabled = true
    UI.TextLabel.Text = Message
    UI.PlayerName.Text = Name.." Tweeted:"
    task.wait(5)
    UI.Enabled = false
end)

the other is to just loop through each player’s playergui from the server and access their ui from there.

1 Like

i got a quick question, do i put the local script into startercharacterscript or starterplayerscripts??

it really doesn’t matter, but you could put it inside the UI you want to move, this way instead of player.PlayerGui.YourUI you could just say script.Parent.

as long as you put it somewhere it runs, in it’s current state it should work.

i get an error “onclientevent” can only be used on clients…

1 Like

oh wait, it was my other script, my bad i didnt notice.

alright so i tried the script’s you sent me and they don’t work.

1 Like

could you tell me the errors?

if the error is onclient event can only be used on the client, then you might have switched the server and client scripts around no?

it just randomly didnt work and it works now, ill just check if it works for everyone not just me.

1 Like

IT STARTED WORKING THANK YOU SO MUCHHHH (idk why it didnt work before)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.