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

Why wont the script fire the event?

Asked by 5 years ago

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

0
Why are you doing a while loop to check their chat message? Just use the .Chatted event. awfulszn 394 — 5y
0
i never heard of that event Gameplayer365247v2 1055 — 5y
0
player.Chatted DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
1
Answered by
awfulszn 394 Moderation Voter
5 years ago

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!

0
wow thanks man that really helped, works exacly as intended Gameplayer365247v2 1055 — 5y
0
No worries, good luck developing! awfulszn 394 — 5y
Ad

Answer this question