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

What is wrong With This chat Bubble script?

I have a Chat Bubble Script that if a Player Talk The chat bubble over his head will show his Group rank, But it's not working. Please Help!

function clear(char)
local c = char:GetChildren()
	for i = 1,#c do
	if c[i].className == "Model" then
	c[i]:Remove()
	end
	end
end


function onChatted(msg, recipient, speaker) 
	if speaker.Character ~= nil then
		clear(speaker.Character)
		if msg == "RANK" then
			local person = game.Workspace.MainScript.Members:findFirstChild(speaker.Name)
			if person ~= nil then
				local bubble = script.BubbleSpeech:clone()
				bubble.PrevL.Value = 30
				bubble.Name = person.Name.." is rank "..tostring(person.Value)	
				bubble.Head.BrickColor = BrickColor.new("Toothpaste")
				bubble.Parent = speaker.Character
			else
				local bubble = script.BubbleSpeech:clone()
				bubble.PrevL.Value = 30
				bubble.Name = speaker.Name.." is not a member of SS"	
				bubble.Head.BrickColor = BrickColor.new("Toothpaste")	
				bubble.Parent = speaker.Character
			end
		else
		
			if string.len(msg) < 101 then
				local bubble = script.BubbleSpeech:clone()
				bubble.Name = msg
				bubble.PrevL.Value = string.len(bubble.Name)
				bubble.Parent = speaker.Character
				bubble.Head.Anchored = false
				bubble.Head.CanCollide = false
			end
			if string.len(msg) > 100 and string.len(msg) < 201 then

				local bubble = script.BubbleSpeech:clone()
				bubble.Name = string.sub(msg,1,100)
				bubble.PrevL.Value = 100
				bubble.Parent = speaker.Character
				bubble.Head.Anchored = false
				bubble.Head.CanCollide = false
				--bubble.Row.Value = 1.5

				local bubble2 = script.BubbleSpeech:clone()
				bubble2.Name = string.sub(msg,100,200)
				bubble2.PrevL.Value = 100 + string.len(bubble2.Name)
				bubble2.Parent = speaker.Character
				bubble2.Head.Anchored = false
				bubble2.Head.CanCollide = false





			end
			if string.len(msg) > 200 and string.len(msg) < 301 then

				local bubble = script.BubbleSpeech:clone()
				bubble.Name = string.sub(msg,1,100)
				bubble.PrevL.Value = 100
				bubble.Parent = speaker.Character
				bubble.Head.Anchored = false
				bubble.Head.CanCollide = false
				--bubble.Row.Value = 3



				wait(0.5)

				local bubble2 = script.BubbleSpeech:clone()
				bubble2.Name = string.sub(msg,100,200)
				bubble2.PrevL.Value = 200
				bubble2.Parent = speaker.Character
				bubble2.Head.Anchored = false
				bubble2.Head.CanCollide = false

				--bubble2.Row.Value = 1.5

				wait(0.5)
				local bubble3 = script.BubbleSpeech:clone()
				bubble3.Name = string.sub(msg,200,300)
				bubble3.PrevL.Value = 200 + string.len(bubble3.Name)
				bubble3.Parent = speaker.Character
				bubble3.Head.Anchored = false
				bubble3.Head.CanCollide = false




			end
		end
	end

end 

function onPlayerEntered(newPlayer) 

	newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end 

game.Players.ChildAdded:connect(onPlayerEntered)

2 comments

0

I'm afraid this script will took too much time to look trough so you are most likely not going to get an answer unless you narrow the problem

0

Sorry for that some people need the hole script to solve it :/

1 answer

I don't know what BubbleSpeech exactly is, but try this:

function clear(char)
	for _,v in pairs(char:GetChildren()) do
		if v:IsA("Model") then
			v:Destroy()
		end
	end
end

game.Players.PlayerAdded:connect(function(p)
	p.Chatted:connect(function(msg)
		if p.Character then
			clear(p.Character)
			if msg == "RANK" then
				local player = workspace.MainScript.Members:FindFirstChild(p.Name)
				local bubble = script.BubbleSpeech:Clone()
				bubble.PrevL.Value = 30
				bubble.Head.BrickColor = BrickColor.new("Toothpaste")
				bubble.Parent = p.Character
				if player then
					bubble.Name = p.Name.." is rank "..tostring(player.Value)  
				else
					bubble.Name = p.Name.." is not a member of SS"	
				end
				if msg:len() / 100 < 1 then
					local bubble = script.BubbleSpeech:Clone()
					bubble.Name = msg
					bubble.PrevL.Value = msg:len()
					bubble.Parent = p.Character
					bubble.Head.Anchored = false
					bubble.Head.CanCollide = false
				elseif msg:len() / 100 > 1 then
					for x = 0, math.ceil(msg:len() / 100) do
						local bubble = script.BubbleSpeech:Clone()
						if x == 0 and math.floor(msg:len() / 100) == 0 then
							bubble.Name = msg:sub(1, 100)
						elseif x > 0 and math.floor(msg:len() / 100) == x then
							bubble.Name = msg:sub((x * 100) + 1, msg:len())
						elseif x > 0 and math.floor(msg.len() / 100) ~= x then
							bubble.Name = msg:sub((x * 100) + 1, (x+ 1) * 100)
						end
						bubble.PrevL.Value = x * 100
						bubble.Parent = p.Character
						bubble.Head.Anchored = false
						bubble.Head.CanCollide = false
					end
				else
					print("Error.")
				end
			end
		end
	end)
end)

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