NastyCore
(NastyCore)
July 24, 2020, 1:19am
#1
So basically this is the script I got
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
local split = msg:split("")
for i, v in pairs(split) do
if split[1] == "!" then
print(msg)
end
end
end)
end)
when I say “!Hello” then
it prints 6 times(changes everytime)
2 Likes
Syclya
(zzz)
July 24, 2020, 1:27am
#2
It prints 6 times because there are 6 letters when looping through.
What is your goal here? Please elaborate.
1 Like
xZylter
(xZylter)
July 24, 2020, 1:30am
#3
I would look into using String Pattern Anchors for checking if the command prefix was used.
NastyCore
(NastyCore)
July 24, 2020, 1:30am
#4
oh
yea I was using for i, v in pairs soo it printed 6 times
Sorry didnt see that
Syclya
(zzz)
July 24, 2020, 1:32am
#5
Why do you need to loop through? Just do splits[1], splits[2] etc.
Also, string.split returns an array, you should have been using ipairs rather than pairs.
1 Like
blokav
(blokav)
July 24, 2020, 1:36am
#6
If you need to split a string into tokens separated by whitespace, you can do something like this:
local tokens = {}
for s in msg:gmatch("%S+") do
table.insert(tokens, s)
end
If you need to get just the first character in a string you can do something like this:
if (msg:sub(1, 1) == "!") then
print(msg)
end
1 Like
jediritz
(jediritz)
July 24, 2020, 1:47am
#7
Using a debounce system might also solve the problem as well.
Debounce - When and Why