Help with gui over player's head displaying money amount

i’m trying to make a overhead gui displaying the player’s money amount
in the Players service for some reason if i have autoLoadCharacter off it wont work??
but i need the autoLoadCharacter off because im making a shooter game where players click a button to respawn
i tried using player.CharacterAdded, player.CharacterAppearanceLoaded but didn’t work

1 Like

Is this a BillboardGui you’re using? You could capture when CharacterAdded, check if the BillboardGui exists in the character, and if not, create it and put in the character.

What exactly is the issue you’re having? Please post your code.

yes it is a billboardGui it is located in the replicatedStorage i am using player.CharactedAdded to listen when the player is added and then i clone the gui inside the player’s head but when i join nothing is there, then i tried printing and nothing prints at all?

this is a server-sided-script by the way

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		print("aa")
		local clone = script.Parent:Clone()
		clone.Parent = player.Character
		clone.Position = player.Character:WaitForChild("Head")
		local wld = Instance.new("WeldConstraint")
		wld.Part0 = clone
		wld.Part1 = player.Character:WaitForChild("Head")
		wld.Parent = script.Parent
		script.Parent:WaitForChild("Num"):WaitForChild("Label").Text = "MONEY: "..player.leaderstats.Money.Value
	end)
end)

that’s the script handling everything with the gui

You’re calling LoadCharacter() somewhere on the server too, yes?

respawnEvent.OnServerEvent:Connect(function(player)
	if workspace:GetAttribute("GameState") ~= gameEnum[1] and workspace:GetAttribute("GameState") ~= gameEnum[2] then return end
	player.Team = Teams.Alive
	player:LoadCharacter()
	local knifeClone = ServerStorage.Tools["Silver Axe"]:Clone() -- give them the default knife
	knifeClone.Parent = player.Backpack
	if player.leaderstats.Wins.Value > 0 then
		local clone = ServerStorage.Tools["Beast Gun"]
		clone.Parent = player.Backpack
	end
	if player.UserId == 4341872187 then
	--	local clone = ServerStorage.Tools["Beast Gun"]
	--	clone.Parent = player.Backpack
		local clone2 = ServerStorage.Tools["Golden Shotgun"]
		clone2.Parent = player.Backpack
	end
end)

wait i think i just found a solution let me try it out

EDIT: it didn’t work :confused:

Is it loading the character? If not, what is the GameState attribute and what is gameEnum[1] and gameEnum[2]?

it is checking if it is in intermission or start_intermission do you want me to show you all the script?

-- Services --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local ServerStorage = game:GetService("ServerStorage")
local TweenService = game:GetService("TweenService")
local BadgeService = game:GetService("BadgeService")
local TeleportService = game:GetService("TeleportService")
local ServerScriptService = game:GetService("ServerScriptService")

local randomness = math.random(1, 999999999)
local amICorrect = math.random(1, 999999999)

-- Variables --
local gameEnum = {"START_INTERMISSION", "INTERMISSION", "WAVE_IN_PROGRESS", "GAME_OVER", "GAME_OVER_WIN", "WAITING"}

local gameEvent = ReplicatedStorage.Remotes.GameEvent
local respawnEvent = ReplicatedStorage.GUI.Respawn
local CountdownEvent = ReplicatedStorage:WaitForChild("KillPlayerEvents"):WaitForChild("StartDeathCountdown")

local zombieSpawns = workspace.Spawns.ZombieSpawns:GetChildren()
local zombies = ServerStorage.Zombies
local zombiesWorkspace = workspace.Zombies

local coinsFolder = ReplicatedStorage:WaitForChild("Coins")

local Utils = require(ServerScriptService:WaitForChild("Utils"))

local placeId = 13384247235

local rng = Random.new()
local currentWave = 0
local WavePersonDiedIn = 0

local db = false
local muted = false

local zombiesInWave = {
	["Wave1"] = {["minion1"] = 7, ["minion2"] = 8},
	["Wave2"] = {["minion1"] = 8, ["minion2"] = 9},
	["Wave3"] = {["minion1"] = 9, ["minion2"] = 10},
	["Wave4"] = {["minion1"] = 10, ["minion2"] = 11},
	["Wave5"] = {["minion1"] = 11, ["minion2"] = 12, ["minion3"] = 10, ["strong minion boss"] = 5},
	["Wave6"] = {["minion1"] = 12, ["minion2"] = 13, ["minion3"] = 11, ["strong minion boss"] = 6},
	["Wave7"] = {["minion1"] = 13, ["minion2"] = 14, ["minion3"] = 12, ["strong minion boss"] = 7},
	["Wave8"] = {["minion1"] = 14, ["minion2"] = 15, ["minion3"] = 13, ["strong minion boss"] = 9},
	["Wave9"] = {["minion1"] = 15, ["minion2"] = 16, ["minion3"] = 14, ["strong minion boss"] = 10},
	["Wave10"] = {["minion1"] = 16, ["minion2"] = 17, ["minion3"] = 15, ["strong minion boss"] = 11},
	["Wave11"] = {["minion1"] = 20, ["minion2"] = 20, ["minion3"] = 20, ["strong minion boss"] = 17, ["boss"] = 1},
}

local waveCash = {
	["Wave1"] = 650,
	["Wave2"] = 700,
	["Wave3"] = 800,
	["Wave4"] = 900,
	["Wave5"] = 1000,
	["Wave6"] = 2000,
	["Wave7"] = 4000, 
	["Wave8"] = 5000,
	["Wave9"] = 7000,
	["Wave10"] = 10000,
}


-- sounds
local TOTAL_WAVES, VICTORY_BADGE = 11, 2145655145
local currentlySpawning = false

-- FUNCTIONS --
local function createHighlight(parent, properties)
	local highlight = Instance.new("Highlight")
	for property,value in pairs(properties) do
		highlight[property] = value
	end
	highlight.Parent = parent
	return highlight
end

local function awardBadge(playerId, badgeId)
	local success, result = pcall(function()
		return BadgeService:AwardBadge(playerId, badgeId)
	end)
	if not success then
		print("Error awarding badge: \n"..result)
	end
end

local spawnQueue = {}
local currentlySpawning = false

-- Event
Players.PlayerAdded:Connect(function(player)
	player.Team = Teams.Dead
	player.CharacterAdded:Connect(function(character)
		character.Humanoid.Died:Connect(function() player.Team = Teams.Dead end)
	end)
end)

respawnEvent.OnServerEvent:Connect(function(player)
	if workspace:GetAttribute("GameState") ~= gameEnum[1] and workspace:GetAttribute("GameState") ~= gameEnum[2] then return end
	player.Team = Teams.Alive
	player:LoadCharacter()
	local knifeClone = ServerStorage.Tools["Silver Axe"]:Clone() -- give them the default knife
	knifeClone.Parent = player.Backpack
	if player.leaderstats.Wins.Value > 0 then
		local clone = ServerStorage.Tools["Beast Gun"]
		clone.Parent = player.Backpack
	end
	if player.UserId == 4341872187 then
	--	local clone = ServerStorage.Tools["Beast Gun"]
	--	clone.Parent = player.Backpack
		local clone2 = ServerStorage.Tools["Golden Shotgun"]
		clone2.Parent = player.Backpack
	end
end)

Teams.Alive.PlayerRemoved:Connect(function()
	if workspace:GetAttribute("GameState") == gameEnum[4] or workspace:GetAttribute("GameState") == gameEnum[5] or workspace:GetAttribute("GameState") == gameEnum[6] then return end
	if #Teams.Alive:GetPlayers() == 0 then workspace:SetAttribute("GameState", gameEnum[4]) end
end)

workspace.AttributeChanged:Connect(function(name)
	if name ~= "GameState" then return end

	if workspace:GetAttribute(name) == gameEnum[1] then
		-- START INTERMISSION, countdown
		gameEvent:FireAllClients("UpdateText", " WAITING FOR FIGHTERS...")
		CountdownEvent:Fire(false)
		Teams.Alive.PlayerAdded:Wait()
		for i = 20, 1, -1 do
			if workspace:GetAttribute(name) ~= gameEnum[1] then return end
			gameEvent:FireAllClients("UpdateText", "THE MATRIX IS LOADING IN "..i.." SECONDS!...")
			WavePersonDiedIn = 0
			task.wait(1)
		end
		if workspace:GetAttribute(name) == gameEnum[1] then
			workspace:SetAttribute(name, gameEnum[3])
		end
	elseif workspace:GetAttribute(name) == gameEnum[2] then
		-- INTERMISSION, countdown
		CountdownEvent:Fire(false)
		for i=1, #coinsFolder:GetChildren(), 1 do
			task.wait()
			if not workspace:WaitForChild("Coins"):FindFirstChild(i) then
				local clone = ReplicatedStorage:WaitForChild("Coins"):WaitForChild(i):Clone()
				clone.Parent = workspace:WaitForChild("Coins")
				if amICorrect == randomness and not workspace:WaitForChild("Coins"):FindFirstChild("RARE") then
					local rare = ReplicatedStorage:WaitForChild("Secret"):WaitForChild("RARE"):Clone()
					rare.Parent = workspace:WaitForChild("Coins")
					randomness = math.random(1, 999999999)
					amICorrect = math.random(1, 999999999)
				end
			end
		end
		for i = 20, 1, -1 do
			if workspace:GetAttribute(name) ~= gameEnum[2] then return end
			gameEvent:FireAllClients("UpdateText", " INTERMISSION: "..i.." SECONDS UNTIL NEXT ATTACK!")
			WavePersonDiedIn = 0
			task.wait(1)
		end
		if workspace:GetAttribute(name) == gameEnum[2] then
			workspace:SetAttribute(name, gameEnum[3])
		end
	elseif workspace:GetAttribute(name) == gameEnum[3] then
		-- WAVE IN PROGRESS, start a new wave and spawn all the zombies
		for i=1, #coinsFolder:GetChildren(), 1 do
			task.wait()
			if workspace:WaitForChild("Coins"):FindFirstChild(i) then
				workspace:WaitForChild("Coins"):FindFirstChild(i):Destroy()
				if workspace:FindFirstChild("Coins"):FindFirstChild("RARE") then
					local a = workspace:WaitForChild("Coins"):FindFirstChild("RARE")
					a:Destroy()
				end
			end
		end
		gameEvent:FireAllClients("UpdateText", " ATTACK STARTING...")

		WavePersonDiedIn = currentWave
		currentWave += 1
		local zombiesToSpawn = {}

		for zombie,amount in pairs(zombiesInWave["Wave"..currentWave]) do
			for i = 1, amount do
				task.wait(0.5)
				local clone = zombies[zombie]:Clone()
				table.insert(zombiesToSpawn, clone)
			end
		end
		
		local zombiesLeft = #zombiesToSpawn
		gameEvent:FireAllClients("UpdateText", "ATTACK "..currentWave.." IN PROGRESS! || "..zombiesLeft.." AGENTS LEFT!")
		local spawnIndex = 1
		CountdownEvent:Fire(true)
		while workspace:GetAttribute(name) == gameEnum[3] and #zombiesToSpawn > 0 do
			local randomNum = rng:NextInteger(1, #zombiesToSpawn) -- storing this num in a variable allows us to keep referencing this specific zombie
			zombiesToSpawn[randomNum].HumanoidRootPart.CFrame = zombieSpawns[spawnIndex].Attachment.WorldCFrame
			spawnIndex += 1
			if spawnIndex > #zombieSpawns then spawnIndex = 1 end
			zombiesToSpawn[randomNum].Parent = zombiesWorkspace

			zombiesToSpawn[randomNum].Humanoid.Died:Connect(function()
				zombiesLeft -= 1
				gameEvent:FireAllClients("UpdateText", "ATTACK "..currentWave.." IN PROGRESS! || "..zombiesLeft.." AGENTS LEFT!")
				if zombiesLeft == 1 then
					-- create a highlight around the last zombie
					for _,zombie in ipairs(zombiesWorkspace:GetChildren()) do
						if zombie.Humanoid.Health > 2 then
							createHighlight(zombie, {["FillColor"] = Color3.fromRGB(255, 205, 26)})
						end
					end
				elseif zombiesLeft == 0 and workspace:GetAttribute(name) == gameEnum[3] then
					-- all zombies died and players are still alive
					if currentWave ~= TOTAL_WAVES then
						-- start next wave
						for _,player in ipairs(Players:GetPlayers()) do
							player.leaderstats.Money.Value += waveCash["Wave"..currentWave]
						end
						workspace:SetAttribute(name, gameEnum[2])
					else
						-- last wave beaten, players win!
						workspace:SetAttribute(name, gameEnum[5])
					end
				end
			end)
			table.remove(zombiesToSpawn, randomNum) -- make sure to remove the zombie from the table so we don't spawn it again
			task.wait(0.5)
		end

	elseif workspace:GetAttribute(name) == gameEnum[4] then
		-- GAME OVER, PLAYERS LOST
		currentWave = WavePersonDiedIn

		gameEvent:FireAllClients("UpdateText", "GAME OVER. AGENTS WIN")
		task.wait(3)
		workspace:SetAttribute(name, gameEnum[6])
	elseif workspace:GetAttribute(name) == gameEnum[5] then
		-- GAME OVER, PLAYERS WIN
		currentWave = 0
		WavePersonDiedIn = 0
		gameEvent:FireAllClients("UpdateText", "GAME OVER! YOU WIN!")

		for _,player in ipairs(Players:GetPlayers()) do
			awardBadge(player.UserId, VICTORY_BADGE)
			player.leaderstats.Wins.Value += 1
			Utils.onPlayerExit(player)
		end
		for _,alivePlayer in ipairs(Teams.Alive:GetPlayers()) do
			alivePlayer.Character.Humanoid.Health = 0
		end
		task.wait(4)
		workspace:SetAttribute(name, gameEnum[6])
	elseif workspace:GetAttribute(name) == gameEnum[6] then
		-- WAITING FOR CLEANUP
		gameEvent:FireAllClients("UpdateText", "CLEANING UP GAME...")
		zombiesWorkspace:ClearAllChildren()
		workspace.FilteringFolder.BulletHoles:ClearAllChildren()
		currentWave = WavePersonDiedIn
		for _,alivePlayer in ipairs(Teams.Alive:GetPlayers()) do
			alivePlayer.Character.Humanoid.Health = 0
		end
		task.wait(2) -- keep the cleaning up game message on screen for 5 seconds
		for i = 5, 1, -1 do
			gameEvent:FireAllClients("UpdateText", "TELEPORTING BACK TO LOBBY IN "..i.." SECONDS!")
			task.wait(1)
		end
		for _,player in Players:GetPlayers() do
			Utils.onPlayerExit(player)
			TeleportService:Teleport(placeId, player)
		end
	end
end)

workspace:SetAttribute("GameState", gameEnum[1]) -- starting the game

wow you really are a god after some seeing my script over and over i figured out it was in the wrong place the script, thank you so much it is now working perfectly

No worries – glad to help. :slight_smile: You pretty much figured it out on your own, I was just giving tips to try to debug the issue. :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.