Chat Log Script

Hi! I’m currently trying to send an HTTP request to my external database everytime a user chats, I already have it sending the username and message however I can’t seem to add math.random?

Here is what I’m trying to do.

game.Players.PlayerAdded:connect(function(Player)
    Player.Chatted:connect(function(Message)
        local Data = {
            ['username'] = Player.Name,
			["content"] = "Player: "..Player.Name.." ".."\nMessage: "..Message.." ".."\nChat Id: "..math.random
        }
        local NewData = HttpService:JSONEncode(Data)
        HttpService:PostAsync(Webhook,NewData)
    end)
end)

Everything works except the math.random part.

You need to add two parameters, the minimum number and the maximum number.

number math.random ( number m = 0.0, number n = 1.0 )
This function is an interface to the simple pseudo-random generator function rand provided by ANSI C. (No guarantees can be given for its statistical properties.) When called without arguments, returns a uniform pseudo-random real number in the range [0,1). When called with an integer number m, math.random returns a uniform pseudo-random integer in the range [1, m]. When called with two integer numbers m and n, math.random returns a uniform pseudo-random integer in the range [m, n].

Also, you should use :Connect instead of :connect.

Not sure I understand, it would be like this?

["content"] = "Player: "..Player.Name.." ".."\nMessage: "..Message.." ".."\nChat Id: "..math.random ( number m = 0.0, number n = 1000.0 )

Hey,
You’re missing the parenthesis for the math.random function which may be why it’s behaving weirdly. Try using math.random() instead, to get something like this:
["content"] = "Player: "..Player.Name.." ".."\nMessage: "..Message.." ".."\nChat Id: "..math.random().

@aixziie

This is incorrect. math.random(), math.random(10), and math.random(1, 10) all work fine. The parameters are optional unless you want to specify them with specifics.

1 Like

No, you don’t need the number m and number n. In the API reference, those are just placeholders, to differentiate the numbers. Math.random using min, max, which is (minimum number, max number)

So you line would be :

["content"] = "Player: "..Player.Name.." ".."\nMessage: "..Message.." ".."\nChat Id: "..math.random (0, 1000)