Need help on my Rolepicking system script isn't working

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 :slight_smile:

1 Like

@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 :slight_smile:

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.

1 Like

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)
1 Like

@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!!

1 Like

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,
4c557c2104046b955883da04a45aa35d

In other words, how the ServerScriptService script?
685dfef86619a2c2b09ea4a63332eb69

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.

1 Like

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.
a7132db5b0c005ae8c9a8b0069e1f68c
945afdc0ce7a534b1497d0e63af34001
47b0ff74a18d681a29aeaf1ed50935d9
Here is my Gui, the name for the role, I just put murderer.
0e54f3138a545f660f2e1d402ccbf352
This is where I put the client code at, in that local script
02d53f72708cf45ce462ec3fb9a3f9dd