So, I am expanding on my other question which was answered. I made a script which makes text appear above your head, but then I have made a different script which if the button is pressed, the text above your head changes, but when re-clicked, it changes back.
Original
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 = {1,3,3,3,3,3,2,1} -- Frequency relative to eachother local Injuries = {"Heart Attack", "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() local id = 2567972 if plr:GetRankInGroup(id) <= 3 then gui.TextLabel.Text = (plr.Name.. ", " .. Injuries[chosenKey]) gui.Adornee = Character:WaitForChild("Head") gui.Parent = Character:WaitForChild("Head") elseif plr:GetRankInGroup(id) >= 4 then gui.TextLabel.Text = (plr.Name.. ", " .. plr:GetRoleInGroup (id)) gui.Adornee = Character:WaitForChild("Head") gui.Parent = Character:WaitForChild("Head") end end) end)
Other Changer
while true do if script.Parent.NameChanger.Disabled == false then else game.Players.PlayerAdded:connect(function(plr) plr.NameDisplayDistance = 0 plr.CharacterAdded:connect(function(Character) local gui = script.BillboardGui:Clone() local id = 2567972 if plr:GetRankInGroup(id) <= 3 then gui.TextLabel.Text = plr.Name gui.Adornee = Character:WaitForChild("Head") gui.Parent = Character:WaitForChild("Head") elseif plr:GetRankInGroup(id) >= 4 then gui.TextLabel.Text = (plr.Name.. ", " .. plr:GetRoleInGroup (id)) gui.Adornee = Character:WaitForChild("Head") gui.Parent = Character:WaitForChild("Head") end end) end) end end
Button
script.Parent.MouseEnter:connect(function(e) local wh = Color3.new(1,1,1) local gr = Color3.new(0,1,0) local bt = script.Parent local cli = script.Sound if bt.TextColor3 == gr then bt.TextColor3 = wh bt.BorderColor3 = wh cli:Play() end end) script.Parent.MouseLeave:connect(function(l) local wh = Color3.new(1,1,1) local gr = Color3.new(0,1,0) local bt = script.Parent local cli = script.Sound if bt.TextColor3 == wh then bt.TextColor3 = gr bt.BorderColor3 = gr cli:Play() end end) function click() local sss= game:GetService("ServerScriptStorage") if sss.NameChanger.Disabled == false then sss.NameChanger.Disabled = true sss.NC2.Disabled = false else sss.NameChanger.Disabled = false sss.NC2.Disabled = true end end local gr = Color3.new(0,1,0) local bt = script.Parent bt.TextColor3 = gr bt.BorderColor3 = gr end script.Parent.MouseButton1Down:connect(click)