Please help with my script

How I want my code to work
I would like for whenever someone say !ToggleMic (username) a notification pops up saying their mic has been toggled, and whenever they type the same command again another notification pops up saying its disabled. Whenever the Mic is enabled I would like for whatever that player says to pop up in a notification until the mic is disabled.

Whats the problem?
The problem is for some reason when the mic is enabled, everyones chat pops up in a notification instead of just the person who did the command.

Local Script

game.ReplicatedStorage.ToggleMicEvents.MicOffNotifierEvent.OnClientEvent:Connect(function(Target)	
	print(Target)
	game.StarterGui:SetCore("SendNotification", {

		Title = "Toggle Mic";
		Text = Target.Name.."'s Mic is off";
		Icon = "http://www.roblox.com/asset/?id=6853258454";
		Duration = "10"

		})
end)

game.ReplicatedStorage.ToggleMicEvents.MicOnNotifierEvent.OnClientEvent:Connect(function(Target)
	print(Target)
	game.StarterGui:SetCore("SendNotification", {

		Title = "Toggle Mic";
		Text = Target.Name.."'s Mic is on";
		Icon = "http://www.roblox.com/asset/?id=257119670";
		Duration = "10"

		})
end)

game.ReplicatedStorage.ToggleMicEvents.ChatNotifierEvent.OnClientEvent:Connect(function(Target, msg)
	print(Target)
	game.StarterGui:SetCore("SendNotification", {
		Title = Target;
		Text = msg;
		Duration = "10"

		})
end)
``

**Server Script**
```lua
--// VARIABLES \\--

local Players = game:GetService("Players")

local Prefix = '!'

local MicStatus = false

local ReadyToTalk = false

local NotTypingCommand = false


--// FUNCTIONS \\--

local function CheckForTarget (Target)    

    if not Target then

        print("Target is not valid")
        return false

    else

        print("Target is valid")
        return true

    end

end



Players.PlayerAdded:Connect(function(player)



    player.Chatted:Connect(function(msg)



        if msg:sub(1, 11) == Prefix.."ToggleMic " and MicStatus == false then

            local Target = Players:FindFirstChild(msg:sub(12))
            local Valid = CheckForTarget(Target)

            if Valid then
                
                script.UserStringValue.Value = Target.Name
                game.ReplicatedStorage.ToggleMicEvents.MicOnNotifierEvent:FireAllClients(Target)

            end

            MicStatus = true
            ReadyToTalk = true

        elseif msg:sub(1, 11) == Prefix.."ToggleMic " and MicStatus == true then

            local Target = Players:FindFirstChild(msg:sub(12))
            local Valid = CheckForTarget(Target)

            if Valid then
                
                script.UserStringValue.Value = nil
                game.ReplicatedStorage.ToggleMicEvents.MicOffNotifierEvent:FireAllClients(Target)

            end

            MicStatus = false
            ReadyToTalk = false
            

        end
        
        
        
        if ReadyToTalk == true then
            
            local Target = script.UserStringValue.Value
            local Valid = CheckForTarget(Target)

            if Valid then
                
                print(script.UserStringValue.Value)
                game.ReplicatedStorage.ToggleMicEvents.ChatNotifierEvent:FireAllClients(Target, msg)

            end
            
        end
        
    end)
    
end)
1 Like

It appears you are doing this on the server, make a RemoteEvent and fire it to the specific client, then do the notification on the client side.

Did you happen to use FireAllClients() in your script (that fires the remote event)? I believe that is the issue. You want to use FireClient() instead, so that the message will only appear for the person who’s mic is enabled.