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

How to fix this Microphone Message script?

I have a working Microphone, that of course works when spoken into from a certain distance. What I would like is before the message is say "Message from (Speakers Name Here)" But i cant seem to get it working? Anyone able to diagnose this problem?

function onChatted(msg, recipient, speaker) 

local source = string.lower(speaker.Name)
msg =(msg)
local pos1 = script.Parent.Position
local pos2 = speaker.Character.Head.Position
dist=(pos1-pos2).magnitude
dist=dist-math.max(math.max(speaker.Character.Head.Size.x, speaker.Character.Head.Size.z), speaker.Character.Head.Size.y)
if (dist <= 5 and script.Parent.On.Value == true) then
local m = Instance.new("Message")
m.Parent = game.Workspace
m.Text = "Message from (speaker.Name): (msg)"
wait(5)
m:remove()
end

end 

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

game.Players.ChildAdded:connect(onPlayerEntered)

From this all I get is, "Message from (speaker.Name): (msg)", which isn't what I want. How do I have the variables actually be replaced by what is stated?

1 comment

0

ALSO: Use the PlayerAdded event, not ChildAdded.

1 answer

✓ Accepted answer

You improperly concatenated the string values in the line where you changed your message. In order to combine a string with variables (that are also strings) you need to use two periods (..) to separate them as seen below in my example:

m.Text = "Message from " .. speaker.Name .. ": " .. msg

1 comment

0

Thank you very much for your assistance! +1~

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