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

Chatted script having problems?

Asked by 10 years ago

The problem area is lines 16-22, where it won't find the player that I'm talking about. The command I would use would be /awarp 001 CardboardRocks to award 1 PP to CardboardRocks. Any ideas as to why this isn't working?

keyword = "/awarp"
local PointsService = Game:GetService("PointsService")

game.Players.PlayerAdded:connect(function(player)
    player:WaitForDataReady()
    pointsToAward = PointsService:GetAwardablePoints()
    player.Chatted:connect(function(msg)

        if string.find(msg:lower(), keyword) then
            print("Found "..keyword)
            a = msg:sub(8, 11)
            print(a)
            c = msg:sub(12, msg:len())
            playerschildren = game.Players:GetChildren()
            for i, v in pairs(playerschildren) do
                if c == v then
print("Through")
                    d = playerschildren[v]
                    print(d.Name)
else
print("Not")
                end
            end
            if pointsToAward > 0 then
                 game:GetService("PointsService"):AwardPoints(d.userId, a)
            end
        end
    end)
end)
0
I believe it's supposed to be "v.Name" Shawnyg 4330 — 10y
0
Protip: `#str` is the same as `str:len()`; `sub`'s second parameter is optional and `sub` defaults to taking remainder of string. In any case, specifying `-1` is the same as specifying `#str`! BlueTaslem 18071 — 10y

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

In your loop, v is a child from the list of players. As such it will be a Player instance. However, c is a string. Since they have different types, the comparison on line 16 will always fail.

We need to compare v's Name with c. It would also be more robust to do this case insensitive, so we should use something like:

if v.Name:lower() == c:lower() then
0
Thank you so much! I finally got it to work changing some other stuff around plus this! CardboardRocks 215 — 10y
Ad

Answer this question