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

Parameter is a nil value?

Asked by
Faazo 84
6 years ago

I made a script that when the button is click, it changes the text to "Taken by <Playername>!". 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

Log in to vote
1
Answered by
doomiiii 112
6 years ago

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)

Ad

Answer this question