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

Overhead GUI not appearing?

Asked by 4 years ago
Edited 4 years ago

Whenever I attempt to start the game with the GUI, it stays invisible and I get this error in the output:

15:34:21.197 - ServerScriptService.Script:14: attempt to index nil with 'PlayerGui'

math.randomseed(tick())
local billboardgui = game:GetService("ServerStorage"):WaitForChild("BillboardGui")

game.Players.PlayerAdded:Connect(function(player)

    player.CharacterAdded:Connect(function(character)

            local clonedgui = billboardgui:Clone()
            clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
            clonedgui.TextLabel.BackgroundTransparency = 1
            clonedgui.TextLabel.TextTransparency = 1
            game.Players.PlayerAdded:Connect(function(player)
    end)
            game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton.MouseButton1Click:Connect(function()
            clonedgui.TextLabel.BackgroundTransparency = 0.45
            clonedgui.TextLabel.TextTransparency = 0
            clonedgui.TextLabel.Text = math.random(1, 20)
            wait(0.3)
            clonedgui.TextLabel.Text = math.random(1, 20)
            wait(0.3)            
            clonedgui.TextLabel.Text = math.random(1, 20)
            wait(0.3)
            clonedgui.TextLabel.Text = math.random(1, 20)
            wait(0.3)
            clonedgui.TextLabel.Text = math.random(1, 20)
            wait(0.3)
            wait(1)
            clonedgui.TextLabel.BackgroundTransparency = 1
            clonedgui.TextLabel.TextTransparency = 100

        end)
    end)
end)

1 answer

Log in to vote
0
Answered by
Fifkee 2017 Community Moderator Moderation Voter
4 years ago

The server isn't a player. It's a phyiscal server, which can't possibly even manage to press the W key on a physical keyboard. You already have the "player" variable defined for you, so use that!

You should also remove the PlayerAdded connection inside of your CharacterAdded connection. It will be connected to every time any player respawns, which will bloat up your game--unnoticeable at first, but it's definitely out there for you.

Also, use a for loop.

for i = 1, 5 do
    wait(0.3);
    clonedgui.TextLabel.Text = math.random(1, 20);
end
wait(1)

You also never set the BillboardGui's adornee, which is pretty funky. The adornee property (requires an object or nil) tells the BillboardGui to attach to the object provided.

With that out of the way, you should make some changes.


On line 09, you should use character.Head. You have the character variable, so use it.

TextTransparency should only take a value of 0 to 1. 100 is completely unnecessary.

Line 12 and 13 need to go.

You should define all the properties of the descendants of BillboardGui before you parent the billboard itself.

On line 14, use the player variable instead of trying to reference a LocalPlayer.

This line is going to be removed anyway, but use workspace instead of game.Workspace. It has a keyword, so you should probably use it.


If I messed up, let me know. Be sure to mark as answer and upvote if this helped you out a bit. Cheers.

0
After modifying it slightly, how would I use the player variable? Would it just be "game.Players.PlayerAdded:Connect(function(player)" or what? bu77_eater 11 — 4y
0
Nevermind, figured it out! I had to use: game.Players:WaitForChild(player.Name).PlayerGui.ScreenGui.TextButton.MouseButton1Click:Connect(function() bu77_eater 11 — 4y
0
good job! Fifkee 2017 — 4y
Ad

Answer this question