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

How do I define "player"?

Asked by 9 years ago

I'm making a script, and in the output, the only error is that I haven't defined the player, its for a script to equip a tool in a GUI, for a inventory system I made, but the function is : "script.Parent.MouseButton1Click:connect(function(player)", but I need to define player to define the pickaxe. So how would I define the player, here is the code :

local pickaxe = player.Backpack:FindFirstChild("Pickaxe")
--------------------------- "player" definition needed here
script.Parent.MouseButton1Click:connect(function(player)
    local pickaxe = player.Backpack:findFirstChild("Pickaxe")
    if script.Parent.Text == "Unequip" then
        pickaxe.Parent = game.ServerStorage
        script.Parent.Text = "Equip"
    else
        pickaxe:Clone().Parent = player.Backpack
        script.Parent.Text = "Unequip"
    end
end)

2 answers

Log in to vote
0
Answered by 9 years ago

If your code is in a local script you can define player with the following code:

local player = game.Players.LocalPlayer

LocalPlayer is a property in game.Players that returns Player only if it is called in a localscript, calling in a regular script will result in error

Tips on localscripts

  • localscripts should only be used inside StarterGui or StarterPack or anywhere thats within the Player object. it can also be used in tools/hopperbins
0
But what do I do if it ISN'T a local script. I even stated in my question that its a normal "script". KennySfromTitan 106 — 9y
0
By the looks of it the script is under PlayerGui/StartGui just put the code in a localscript and use that DragonSkyye 517 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

just say this in your script

game.Workspace.player

Answer this question