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

GUI is only being given to each player when they join but not re spawn? [ answered ]

Asked by 3 years ago
Edited 3 years ago

( I answered this myself fell free to check out what I did and use it in your game if you like ) Right now I'm trying to make a script that makes a starting screen appear for players in the lobby team it works but if the player resets or dies the GUI is not loaded in again if they are at the lobby team. Here is the script fell free to ask me any questions about it

local Players = game:GetService("Players")
local teams = game:GetService("Teams")

local function onCharacterAdded(character)
    print(character.Name .. " has spawned")
    local respawning_player = game.Players:FindFirstChild(character.Name)
    print("player has been found")
    if respawning_player.Team == teams.Lobby then
        print(character.Name .. " is in the lobby")
        local Starting_Screen = game.ServerStorage.UI.StartingScreen:Clone()
        Starting_Screen.Parent = respawning_player.PlayerGui
        print(character.Name .. " now can see the starting screen")
    end
end

local function onCharacterRemoving(character)
    print(character.Name .. " is despawning")
end

local function onPlayerAdded(player)
    player.CharacterAdded:Connect(onCharacterAdded)
    player.CharacterRemoving:Connect(onCharacterRemoving)
end

Players.PlayerAdded:Connect(onPlayerAdded)
0
Try setting the ResetOnSpawn property of your GUI to true. AntiWorldliness 868 — 3y
0
Its already set to true robloxian_colby 22 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

After a couple hours of testing I finally fixed it, and here is the script. The main thing I did was add the wait(0.2) at line 8 this made it work not exactly sure why but it works now, so here you go ( if you know why this happened I would like it if you committed it thanks )

local Players = game:GetService("Players")
local teams = game:GetService("Teams")

local function onCharacterAdded(character)
    print(character.Name .. " has spawned")
    local respawning_player = game.Players:FindFirstChild(character.Name)
    if respawning_player.Team == teams.Lobby then
        wait(0.2)
        local Starting_Screen = game.ServerStorage.UI.StartingScreen:Clone()
        Starting_Screen.Parent = respawning_player.PlayerGui
        print(respawning_player.Name .. " now can see the starting screen")
    end
end


local function onPlayerAdded(player)
    player.CharacterAdded:Connect(onCharacterAdded)
end

Players.PlayerAdded:Connect(onPlayerAdded)

( more notes how to use it ) -- Put this as a normal script in workspace -- In line 9 the .UI is a folder just remove this if you don't want it to be in a folder

Ad

Answer this question