Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Cloning, GUI's, Text Editing help?

So, the script doesn't do the function nor does it clone the GUI into the player. Any help would be appreciated.

What it's meant to do -Clone a billboard GUI above the player's head. -Player's name here, random injury here.

local names = {
	Common = {
		"Chest Pain";
		"Abdominal Pain";
		"Broken Leg";
		"Broken Arm";
		"Headache";
	};
	eh = {
		"Toothache";
	};
	Rare = {
		"Foreign Object";
	};
}

local common,eh,rare = .6,.9,1
game.Players.PlayerAdded:connect(function(plr)
	plr.NameDisplayDistance = 0
	plr.CharacterAdded:connect(function(chr)
	local random = math.random()
	local gui = script.BillboardGui:Clone()
	if random >= 0 and random <= common then
		gui.TextLabel.Text = names.Common[math.random(1,plr.name, #names.Common)]
	elseif random >= common and random <= eh then
		gui.TextLabel.Text = names.eh[math.random(1,plr.name, #names.eh)]
    elseif random >= eh and random <= rare then
		gui.TextLabel.Text = names.Rare[math.random(1,plr.name, #names.Rare)]
	end
		gui.Parent = chr
		gui.Adornee = chr:WaitForChild("Head")
	end)
end)

2 comments

0

Might help if you move the Adornee line and the gui.Parent line to where it clones.

0

@Thundermaker300 Now says "Label"

1 answer

✓ Accepted answer

I made your random injury picker clearer, and the script should be cleaner because of it. I also think it will help if you Parent the BillBoardGui to the PlayerCharacter's Head, after you set the adornee. Let me know if this helped!

local function sum(tab)
	local sum = 0
		for _, value in pairs(tab) do
			sum = sum + value
		end
	return sum
end

local function overflow(tab, seed)
	for i, value in ipairs(tab) do
		if seed - value <= 0 then
			return i, seed
		end
		seed = seed - value
	end
end

local InjuryRarity	= {3,3,3,3,3,2,1} -- Frequency relative to eachother
local Injuries		= {"Chest Pain", "Abdominal Pain", "Broken Leg", "Broken Arm", "Headache", "Toothache", "Foreign Object"}

game.Players.PlayerAdded:connect(function(plr)
	plr.NameDisplayDistance = 0
	plr.CharacterAdded:connect(function(Character)
		-- Get random injury
		local seed			= math.random(1, sum(InjuryRarity))
		local chosenKey		= overflow(InjuryRarity, seed)

		local gui = script.BillboardGui:Clone()
		gui.TextLabel.Text = Injuries[chosenKey]
		gui.Adornee = Character:WaitForChild("Head")
		gui.Parent = Character:WaitForChild("Head")
	end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.