Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to make a simple 'kill command' in Roblox Studio where you type ";kill player" and it will kill them.

The part I am struggling with is how on earth to separate the words before and after the space, and store them as variables?

Steps I need in my code:

  1. Check if the message deliverer's name is equal to the value of 'Owner'
  2. Check if the message contains ';' at the beginning (the prefix)
  3. Check if the message contains one space
  4. If all of the above are true, Then set the word before the space to the variable,'cmd' and set the word after the space to the variable, 'username'.

The rest I can figure out on my own.

Here's what my code is currently:

local Owner = "Djraco"
local Prefix = ";"


game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg)
        
         --<code goes here>

    end)

end)

Thanks in advance!

question from:https://stackoverflow.com/questions/65856084/detect-parameters-in-a-roblox-players-message-lua

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

local Owner = "Djraco"
local Prefix = ";"


game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg)
        
         local msg = msg:split(" ")  -- Seperate your message every space
         if player.Name == Owner and msg[1] == "kill" and msg[2] ~= nil then game:GetService("Players")[msg[2]].Character.Humanoid.Health = 0 end
         

    end)

end)

The above should work. Let me know if you need more help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...