Script not printing after checking if a player that joined has voice chat

I want to check if a player has voice chat when they join, then print out either “success” if they have voice chat, or “fail” if they don’t have voice chat.

This is what I have so far:

local Players = game:GetService("Players")
local VoiceChatService = game:GetService("VoiceChatService")
local LocalPlayer = Players.LocalPlayer

game.Players.PlayerAdded:Connect(function()
if VoiceChatService:IsVoiceEnabledForUserIdAsync(LocalPlayer.UserId) then
	print("success")
else
	print("fail")
	end
end)

I don’t have voice chat, but I should see “Fail” in the output. I don’t.

Someone please tell me what I did wrong and how to fix it!

It appears that you forgot to create a variable to get the service BadgeService

Oh I did, I meant to delete that line so I could simplify the script for the post. I fixed it now.

1 Like

I noticed you are accessing LocalPlayer, so I will assume this script has Client RunContext. If you are only single-player testing, you will have joined before your code begins to listen for PlayerAdded.

It still doesn’t work. How do I fix?

local Players = game:GetService("Players")
local VoiceChatService = game:GetService("VoiceChatService")
local LocalPlayer = Players.LocalPlayer

if VoiceChatService:IsVoiceEnabledForUserIdAsync(LocalPlayer.UserId) then
	print("Has voice chat enabled.")
else
	print("Doesn't have voice chat enabled.")
end

Should this be in a regular script? It is in a local script, there was no error or output. I changed it to a regular script, and it says attempt to nil index with UserId.

It should be in server script and try this

game.Players.PlayerAdded:Connect(function(plr)
	if game:GetService("VoiceChatService"):IsVoiceEnabledForUserIdAsync(plr.UserId) then
		print("Got VC")
	else
		print("No VC")
	end
end)

it still doesn’t work :sob: why is this so hard to do

make sure you checking from roblox game because sometimes roblox studio may not work properly

I did, nothing outputted.

Summary

This text will be hidden

Use the script I posted, currently IsVoiceEnabledForUserIdAsync only works inside LocalScripts and only works for the LocalPlayer’s UserId

It still didn’t work, I don’t know why your script isn’t working.