Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Chatted script having problems?

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)

2 comments

0

I believe it's supposed to be "v.Name"

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!

1 answer

✓ Accepted answer

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

1 comment

0

Thank you so much! I finally got it to work changing some other stuff around plus this!

This discussion is preserved as it was. New answers, comments, and votes are closed.