Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a GUI appear when a player joins?

Asked by 3 years ago

How do I make a GUI appear when a player joins? This is stupid complicated for me sadly.

Remote event that fires when a player joins (script)

local event = game.ReplicatedStorage
local Players = game:GetService("Players")

game.Players.PlayerAdded:Connect(function(player)
    event.qeqeqeq:FireClient(player)
end)

This is the gui that got fired (local script)

event.qeqeqeq.OnClientEvent:connect(function(plr)
    game.Players.CharacterAutoLoads = false
    Player.Humanoid.Health = 0
    script.Parent.Parent.Parent.MenuButton.Visible = false
    script.Parent.Parent.Parent.Menu.Visible = true
    PlayerGUI.HealthGui.Enabled = false
    PlayerGUI.StatusUI.Enabled = false
    PlayerGUI.CurrentVersion.Enabled = false
    game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
    SG:SetCoreGuiEnabled("Backpack", false)
    workspace.CurrentCamera.FieldOfView = 110
    Player.Humanoid.Died:Connect(function()
        Player:Remove()
    end)
    end)

THIS script works in studio but when I join a game it doesn't work for some reason.

0
Note: How do I also prevent the player from respawning (this happens sometimes) when they join? TheBuliderMC 84 — 3y

2 answers

Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
3 years ago
Edited 3 years ago

There most likely explanation is that when you play the game outside of studio, PlayerGui (and all its local scripts) load much slower. So when server fires and event to the client, this your LocalScript have not loaded yet.

Elegant solution would be for a client to fire a special "Ready" event, so that server could fire its own event. Most people however are happy with adding wait(10) (10 seconds is a pure guess here), before firing any Remotes to clients.

However. Since you want all of this to happen on player join, why use event at all? you can simply get rid of the function and just put this code directly in any local script.

EDIT: If do not want it to run or reset, place it in StarterPlayerScripts or in ScreenGui with ResetOnSpawn property set to false

--proper way to get player in LocalScripts:
local Player = game.Players.LocalPlayer

game.Players.CharacterAutoLoads = false -- this should be done on server, has no effect here.

Player.Humanoid.Health = 0
script.Parent.Parent.Parent.MenuButton.Visible = false
script.Parent.Parent.Parent.Menu.Visible = true
PlayerGUI.HealthGui.Enabled = false
PlayerGUI.StatusUI.Enabled = false
PlayerGUI.CurrentVersion.Enabled = false
Player.CameraMode = Enum.CameraMode.Classic
SG:SetCoreGuiEnabled("Backpack", false)
workspace.CurrentCamera.FieldOfView = 110

Player.Humanoid.Died:Connect(function()
    Player:Remove()
end)

And finally, most of this stuff can be set in studio settings. Click on Players in studio to switch off CharacterAutoLoads in properties window for example. You can also set Gui Elements to Visible, and hide them by clicking on the "Eye" icon in the top right corner, when you are not editing GUI.

0
Thing is that I tried to have the script play in the GUI to something similar that you showed me. It didn't work unless I'm doing something in correctly. CharacterAutoLoads is disabled on player and I keep spawning still. TheBuliderMC 84 — 3y
0
^ I'm 100% sure I don't have any script that edits player spawns TheBuliderMC 84 — 3y
Ad
Log in to vote
-1
Answered by 3 years ago

Yo, TheBuilderMc. How about making the gui visible when the person joins the game LOL

0
if you make the gui visible. then it will appear Not_Paulo 4 — 3y
0
Try to understand the question then answer, thats the point of this website AntoninFearless 622 — 3y

Answer this question