Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.6k views
in Technique[技术] by (71.8m points)

variables - Detect parameters in a ROBLOX player's message? (LUA)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...