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

"plr is a nil value" How?

This is the main coding part it comes to.

submit.MouseButton1Click:Connect(function(plr)
	local data = {
		['username'] = plr.Name,
		['content'] = "Question = "..question.. "Response = "..response.Text
	}
	local snap = http:JSONEncode(data)
	http:PostAsync(url,snap)
end)

It keeps saying the "plr" is nil. Why is that?

2 comments

0

That happens because the normal server script can't get the player who clicked it, you will need a local script and a server script with remotes and stuff to get the actual definition of plr

0

Use a clickdetector, problem solved.

2 answers

✓ Accepted answer

So I'm unsure of the full context of this, but you're using this in a weird way.

A few points I need to make. This should be in a local script. MouseButton1Click is something that will be handled on the client, and as such belongs in a local script. With that established ask yourself a few things.

Is this in a local script? Is the local script on the client? Client meaning somewhere on the client like "ClientScripts" or "PlayerGui" or even the backpack.

My second point. Since you should be using this in a local script, the easiest way to find the player is to do:

game.Players.LocalPlayer

That will give you your player, and should be the same player used to click the mouse button, since it's local.

Another thing. I'm not sure that "MouseButton1Click" actually has anything it will send when fired. The wiki doesn't appear to have anything.

If you want some more help, check out roblox's wiki: https://developer.roblox.com/en-us/api-reference/event/GuiButton/MouseButton1Click

Hope this helps.

my thought is that you didn't define "plr" as a player in your script or roblox doesn't interpret the word "plr" as a real player thing.

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