Ok so I would test this code on a, 2 player server test right? Will the Gui I made also pop up if I use this?
I am not asking you for scripts, don’t take this the wrong way
Ok so I would test this code on a, 2 player server test right? Will the Gui I made also pop up if I use this?
I am not asking you for scripts, don’t take this the wrong way
I would recommend using three or four just to be sure. In reality you would want to test all possible cases, so 1, 2, 3 etc players.
Your GUI will only pop up if you implement the RemoteClientEvent as well as the client side listener. I have no problem writing some code for you
@Vozcom Actually, it would still work - math.random throws an exception when the maximum value is less than the minimum value
OP, @hoosmany, you should provide what was in the output, so it can assist everyone else to solve the problem. The problem is that a player doesn’t have a StarterGui
object in them. StarterGui holds everything that will be cloned to the player’s PlayerGui
upon joining the game. So change all StarterGui
to PlayerGui
Thank you,
I have no problem writing some code for you
I appreciate that, and the help you have help me a lot, all of you scripters have, thank yall very much, it really teache’s me.
That’s not the only problem. The server cannot access let alone mutate a players UI. All UI modification must be done on the client if the game is running FE.
I had my script at PlayerGui
I thought that was causing the script to mess up but that wasn’t the case. They will be getting change back to Player Gui
though.
Here is the server sided code you would need to make this work. If you copy/paste this code you will need to create a new RemoteEvent in the ReplicatedStorage base directory with the name “UIPopUpEvent”.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local uiPopUpEvent = ReplicatedStorage:WaitForChild("UIPopUpEvent")
--Grab array of players
local players = game.Players:GetChildren()
local murderer = players[math.random(#players)]
local survivors = {}
--Pick and alert murderer
uiPopUpEvent:FireClient(murderer, "Murderer")
--Alert survivors
for _, survivor in pairs(players) do
--Don't overwrite murderer as a survivor
if (survivor == murderer) then
continue
end
--Add survivor to an array and alert survivor
table.insert(survivors, #survivors+1, survivor)
uiPopUpEvent:FireClient(survivor, "Survivor")
end
And finally here is you client sided code.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local uiPopUpEvent = ReplicatedStorage:WaitForChild("UIPopUpEvent")
--Setup PopUp GUI everytime server fires ClientEvent
uiPopUpEvent.OnClientEvent:Connect(function(playerType)
--Set text to playerType (Server determines either "Murderer" or "Survivor")
gui.TextLabel.Text = playerType
gui.Visible = true
end)
@MrAsync thanks for the big help, this is going to help me a lot, for the gui I can create any gui i want, and name it gui for it will work?
You can name it whatever you’d like! Here’s some code that will set you up! I’m using a lot of :WaitForChild()'
s so you won’t have and issues in which the UI wouldn’t be loaded yet. This will make it simpler for you.
If this works mark this as the solution so others know you issue has been resolved!
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local uiPopUpEvent = ReplicatedStorage:WaitForChild("UIPopUpEvent")
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local popUpUI = playerGui:WaitForChild("YOURNAMEHERE")
--Setup PopUp GUI everytime server fires ClientEvent
uiPopUpEvent.OnClientEvent:Connect(function(playerType)
--Set text to playerType (Server determines either "Murderer" or "Survivor")
gui.TextLabel.Text = playerType
gui.Visible = true
end)
Ok thank you, yes sir I will indeed mark your reply as solution if this scipt has work, again thanks a lot for your help I’m going to test it out!!
For the client code I would put that in a local script? Or StarterPlayer?
Has to be a local script if it runs on the client. It should be in StarterGui or StarterPlayerScripts.
I knew that, but the server can actually see all of the client’s PlayerGuis now. I didn’t know about that until recently when I was told about it
For the client code something’s wrong,
In other words, how the ServerScriptService script?
You have to change the variable GUI to popUpGui. You named your local variable popUpUI
but you’re trying to access a local variable gui
which doesn’t exist.
Actually in FE, the server can only see what initially added to the clients PlayerGui. Basically everything you put in StarterGui the server will see. Anything else added post-join will not be replicated.
Well it seem to have not worked maybe you can spot this issue I’m having.
Here is my Gui, the name for the role, I just put murderer.
This is where I put the client code at, in that local script