Hi, basically i want to change the lighting for a specific player when that player types a specific sentence in the chatbox.
I couldn’t find a specific answer on the developer forums.
Hi, basically i want to change the lighting for a specific player when that player types a specific sentence in the chatbox.
I couldn’t find a specific answer on the developer forums.
Just use a local script.
Should look something like this:
player.Chatted:Connect(function(message)
if string.find(message:lower(), StringToDetect:lower()) then
-- rest of the code
end
end)
I have already used a LocalScript to write this code.
I’ve tried putting this into a server script and it worked!
What I tried is this:
local StringToDetect = "2009 october incident"
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if string.find(msg:lower(), StringToDetect:lower()) then
local effect = game.ReplicatedStorage.uncannyEffect
local cloneffect = effect:Clone()
clonefect.Parent = game.Lighting
end
end)
end)
Also, in your original script, there was no need to check if the player is the player, because it activates when that player chats, therefore it will always pass. It’s like typing if true == true.
Thank you for the help but since i want the effect to be showed on a specific player and not to everyone this isn’t exactly what i needed
has the player variable been set before the “player.chatted” because you can’t really do anything if it haven’t been set before
Yes i actually did that i just couldn’t screenshot rest of the code.
You can use a RemoteEvents for that
Put a RemoteEvent in replicatedstorage called like “incident”
Make a local script and put it into StarterGui or something
put the contents of this localscript to:
game.ReplicatedStorage.incident.OnClientEvent:Connect(function()
local effect = game.ReplicatedStorage.uncannyEffect
local cloneffect = effect:Clone()
clonefect.Parent = game.Lighting
end)
and change the script’s contents to:
local StringToDetect = "2009 october incident"
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if string.find(msg:lower(), StringToDetect:lower()) then
game.ReplicatedStorage.incident:FireClient(plr)
end
end)
end)
You could try using RemoteEvents, so when the player says the thing, you fire the event.
heres kind of how it would look like:
Script:
local StringToDetect = "2009 october incident"
local event = --put event here
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if string.find(msg:lower(), StringToDetect:lower()) then
event:FireClient(plr)
end
end)
end)
LocalScript:
local event = --put event here again
event.OnClientEvent(function()
local effect = game.ReplicatedStorage.uncannyEffect
local cloneffect = effect:Clone()
cloneffect.Parent = game.Lighting
end)
The problem with putting PlayerAdded
in a LocalScript is that the LocalScript loads in after the player, so it wont pick up the event.
I couldn’t thank you enough. Not only did you make the code simpler, but you also informed me about which type of script to use and how to use RemoteEvents.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.