so whenever a player types and is 5 studs within the part then it should like show the message that he has typed and also this clones the screengui even if u are not 5 studs away it still clones it
local mic = workspace.AnnouncerTable.MIC.Main local range = 5 game.Players.PlayerAdded:Connect(function(p) p.CharacterAdded:Connect(function(char) p.Chatted:Connect(function(msg) while true do if char ~= nil then local torso = char.Torso if (mic.Position-torso.Position).magnitude <= range then local screengui = Instance.new("ScreenGui",p.PlayerGui) screengui.Name = "Announcement" local textlabel = Instance.new("TextLabel",p.PlayerGui:FindFirstChild("Announcement")) textlabel.Text = msg:lower() textlabel.Size = UDim2.new(1,0,1,0) textlabel.TextScaled = true textlabel.BackgroundTransparency = .8 print(p.Name.." Is close") wait(1) screengui:Destroy() break end end end) end) end)
Using a while loop in chatted even when you don't need to.
local mic = workspace.Mic --some part in workspace local range = 5 --in studs btw game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(char) player.Chatted:Connect(function(msg) --You should only have a while loop when you want to run the same code --You're only doing this once every Chatted event so just lose the while --Check to see if player isn't dead if char.Humanoid.Health > 0 then --Every R6 or R15 character has a HumanoidRootPart. Better than using torso. local hrp = char:WaitForChild("HumanoidRootPart") --Check distance if (mic.Position-hrp.Position).magnitude <= range then local screengui = Instance.new("ScreenGui") screengui.Name = "Announcement" --You don't even need to rename this screengui.Parent = player.PlayerGui --because you defined the new instance local textlabel = Instance.new("TextLabel") textlabel.Text = msg:lower() textlabel.Size = UDim2.new(1,0,1,0) textlabel.TextScaled = true textlabel.BackgroundTransparency = .8 textlabel.Parent = screengui print(player.Name.." is close") --debug print could be at the start of the if-statement game:GetService("Debris"):AddItem(screengui, 1) --Same thing as before end end end) end) end)
edit: fix format
The one thing this doesn't do is let other player's see it. You can just use a for loop to create one for each player. Should be easy to do for you but let me know if you need help on that.
Let me know if you need more explanation.