local script:
local rep = game:GetService("ReplicatedStorage") local remote = rep:WaitForChild("RemoteEvent") local chat = game:GetService("Players").world_kiIIer:WaitForChild("Chat") while true do wait(0.1) if chat.Frame.ChatBarParentFrame.Frame.BoxFrame.Frame.ChatBar.Text == "/goto klep" then remote:FireServer() end end
server script works just not this local script
You're using a while
loop to continuously check their chatbox, however this is inefficient and quite redundant.
You could just simply use the .Chatted
event to run a function whenever a player talks, and then compare their message to what you want to say, and such.
I'm assuming you wish for the player "world_kiIIer" to be the only one able to use this.
Note: This should be in a LocalScript
located somewhere inside the player, so place it inside of StarterGui
as it will be cloned to PlayerGui
.
Let's set up our variables:
local rep = game:GetService("ReplicatedStorage") local remote = rep:WaitForChild("RemoteEvent") local player = game.Players.LocalPlayer
Now we can use the .Chatted
event to wait for a player to speak in chat, and then run the function.
You'll notice msg
, we will use this to compare their message.
player.Chatted:Connect(function(msg)
Now, since you only want one person to be able to use this, lets stop running the code if their name is not equal to "world_kiIIer".
if player.Name ~= "world_kiIIer" then return end
Now let's read the player's message, and if it is equal to what you wish for them to say, we can run the code inside.
if msg:lower() == "/goto klep" then remote:FireServer() end
We use the :lower()
method to change their message into all lowercase characters, so the code will still run even if they have a mixture of both uppercase and lowercase letters.
If it is equal to the string, then we will fire the event.
Full code:
local rep = game:GetService("ReplicatedStorage") local remote = rep:WaitForChild("RemoteEvent") local player = game.Players.LocalPlayer player.Chatted:Connect(function(msg) if player.Name ~= "world_kiIIer" then return end if msg:lower() == "/goto klep" then remote:FireServer() end end)
Read more about the .Chatted
event here.
If you have any comments or queries, let me know!
Happy scripting!