Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make my local script run when a specific player sends a specific message?

Asked by 5 years ago
Edited 5 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

How do i make my local script run when a specific player sends a specific message?. Like i want the color of the part at workspace to be changed when a specific player sends a specific message. The code i want to be executed when the specific player sends a specific message:

game.Workspace.BrickColor = BrickColor.Random()

1 answer

Log in to vote
0
Answered by 5 years ago

Connect the function to Player.Chatted event, where the first parameter is the message of the player who chatted.

NOTE: Changing a property in a LocalScript will not cause any changes on the server, thus other clients can't see that the BrickColor of the part has been changed. Also, BrickColor is not a property of Workspace.

To make it work in a LocalScript, first you have to specify who would you like to check. Then create a Chatted event to their Player object in order to check if the specified player is sending the corresponding message.

Here's the full demonstration on how to use it:

--You can try playing with this LocalScript, but with a few modifications to fulfill your needs.
--Unless that, consider this is just a reference
local plrs = game.Players
local localplr = plrs.LocalPlayer

local name = "NotKeanuReeves" --Can be any name of any players.
-- In case if YOU are the sender, set this field to localplr.Name
-- In another case if you don't know the name of the target, you can try indexing the Player list using a for loop, then pick a player under certain conditions, then get their name, or just simply get their player object and set it in a precreated variable.

local plr = game.Players[name] --Get their player object using the name of the player

plr.Chatted:Connect(function(msg)
    if msg == "you big noob" then --check if player is sending the correct message
        workspace.PartToChangeColor.BrickColor = BrickColor.Random() -- then do your thing. Also, "workspace" here is a global namespace that works just like game.Workspace.
    end
end)

--end of story
0
Thank you so much, also "you big noob" xD GodlyEricGamer1800 -100 — 5y
0
how dare u insult me ima repot!!!1!!1! Afterl1ght 321 — 5y
0
xD GodlyEricGamer1800 -100 — 5y
Ad

Answer this question