Highlight Player By command

Hey there! i just wanted to ask some question about my script.
So i want to create an command that when the command is chatted, Players will get highlighted i have a script and here is it:

This 1st picture is A localscript which is parented to the StarterPlayer

And the 2nd pic is an script and parented to ServerScript

I tried using Remoteevent to connect each other, in the server script, i get the Player and character and created an Highlight on script that enables whenever the command is chatted and fire the remote on the localscript. i dont know why it doesn’t work can anyone help me on this?

2 Likes

I’d also created an 2 Remote events for different commands, “Perk1” is for enabling the highlight to users, and “Perk2” is for disabling the highlight on users.

I tried re-updating the script thinking it would work but it didn’t. check it out!


I removed the "local functions"but it still doesn’t

Please any response would help and appreciated!

1 Like

The code you’ve written appears to be a LocalScript, which should be listening for chat messages from the local player. However, the Player.Chatted event does not fire for LocalPlayer in LocalScripts due to Roblox’s security measures. Chat messages are handled by the server, so you should be listening for chat messages in a Script, not a LocalScript.

Here’s what you need to do to fix this:

You should have a Script within ServerScriptService that listens for all player’s chat messages like so:

-- Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local perk = ReplicatedStorage:WaitForChild("Perk1")
local perk2 = ReplicatedStorage:WaitForChild("Perk2")

local config = {
	command1 = "?ex",
	command2 = "?p",
}

local function onPlayerChatted(player, message)
	if message:lower() == config.command1 then
		perk:FireClient(player, true)  
	elseif message:lower() == config.command2 then
		perk2:FireClient(player, false)
	end
end

-- Connect the player's Chatted event when they join
local function onPlayerAdded(player)
	player.Chatted:Connect(function(message)
		onPlayerChatted(player, message)
	end)
end

-- Connect all current and future players
Players.PlayerAdded:Connect(onPlayerAdded)
for _, player in pairs(Players:GetPlayers()) do
	onPlayerAdded(player)
end

The LocalScript should only handle the client-side effects when the RemoteEvent is fired. It should not handle chat events.

-- Local Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local perk = ReplicatedStorage:WaitForChild("Perk1")
local perk2 = ReplicatedStorage:WaitForChild("Perk2")
local player = Players.LocalPlayer

perk.OnClientEvent:Connect(function()
	print("Perk1 was fired!")
	-- Handle the enabling of highlight here
end)

perk2.OnClientEvent:Connect(function()
	print("Perk2 was fired!")
	-- Handle the disabling of highlight here
end)

1 Like

Where will i put this script??

1 Like

image
It seems not to be working, i put the localscripts inside of StarterPlayer and created an line to get the player character and parented the highlight to the player once the command is chatted

This is the updated script

Man, i think you forgot to set the outline transparency to 0 on the perk 1 and outline transparency 1 on the perk 2. (Don’t forget the enabled thingy too.)

Nope it set the OutlineTransparency zon Purpose

You forgot to set the highlight’s parent