PlayerChatted Event Only Firing Once

Alright, so I want a RemoteEvent to be fired whenever a player chats.
Right now, the script only fires once and then if the player chats again it doesn’t fire again.

I’ve tried putting it all locally i.e. moving the playerchatted event into a localscript in StarterGUI, however, this still doesn’t work.

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		game.ReplicatedStorage.Remotes.DialEvent:FireClient(player, msg) -- DialEvent is the remote event
	end)
end)

I took this script from the roblox wiki:
https://developer.roblox.com/en-us/api-reference/event/Player/Chatted

This is the script I made for the local end of it. This is a local script in StarterGUI (I wasn’t sure where to put it and StarterGUI has worked for me in the past.).

game.ReplicatedStorage.Remotes.DialEvent.OnClientEvent:Connect(function(player, msg)
	if msg == "test" then
		tween1:Play()
	else
		tween2:Play()
	end
end)

I cut it down so it isn’t my million and one variables. The script just tweens and object when the event is activated but like I said earlier only works once.

I only really know basic scripting, so I have no idea how I’d go about fixing this.
If you need anymore info feel free to ask me.
Also this is my first topic on here so sorry if I have done anything wrong.

You dont put player in an OnclientEvent, as you can just get the localplayer for those cases.

And I recommend putting the localscript in StarterPlayerScripts to ensure the event connections are only made once, as in StarterGui, it is made everytime you respawn

And if you want to do this locally without the need of a RemoteEvent, remove the PlayerAdded and reference the player directly with the LocalPlayer property of the Players service, PlayerAdded has no time to detect your player being added as the event is made after your player was created

2 Likes

ah thank you so much! It now works!

1 Like