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
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?
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.
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)
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
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.)