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

Parameter is a nil value?

I made a script that when the button is click, it changes the text to "Taken by !". I used a parameter to get the player who clicked it, so it knows what to put in the name, but it says my parameter is a nil value. Here is my script

local function OnClick(Click)
	script.Parent.TakenBy.Text = ("Taken by"..(Click.Parent.Name).."!")
end

script.Parent.MouseButton1Click:Connect(OnClick)

Can someone please help me. Thanks!

1 answer

✓ Accepted answer

It appears, MouseButton1Click callbacks do not have any parameters, so your OnClick function shouldn't either.

However, since GUI + mouse and other input handling code must be in a LocalScript, you can always get the local player like so: local player = game.Players.LocalPlayer

As the LocalScript manual states:

For code run through LocalScripts, the LocalPlayer property of the Players service will return the player whose client is running the script.

You probably want something like this:

local player = game.Players.LocalPlayer

local function OnClick()
    script.Parent.TakenBy.Text = ("Taken by"..(player.Name).."!")
end
	 
script.Parent.MouseButton1Click:Connect(OnClick)

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