When creating a function, its saying this? Please help me.
local function getPlayerFromPart(part) local character = part.Parent if character then local player = game.Players:GetPlayerFromCharacter(character) return player end end
Edit: I am trying to follow a tutorial on how to make a tycoon. This is the full script:
local button = script.Parent local tycoon = script.Parent.Parent.Parent local dirtyRock = game.ReplicatedStorage.DirtyRock local dropper = script.Parent.Parent.Dropper local objectsFolder = local function getPlayerFromPart(part) local character = part.Parent if character then local player = game.Players:GetPlayerFromCharacter(character) return player end end local function dropObject() local newPart = dirtyRock:Clone() newPart.Position = dropper.Position newPart.Parent = objectsFolder end local function onTouched(otherPart) local player = getPlayerFromPart(otherPart) if player then dropObject() end end button.Touched:Connect(onTouched)
The problem is that you don't give the objectsFolder
value an input while still retaining the equals sign. I assume that you want to set its value to nil, so that you can set it to another value later. To do that you can do the following:
local objectsFolder
This will declare objectsFolder
without setting its value. Thus, the value will be nil until it is set to another value.
Removing local would be the solution i think, but since you continue to get an error from somewhere in your function, relating to :GetPlayerFromCharacter
, check if the part.Parent.Name is a member of game.Players or even has a humanoid on it. That error consists somewhere outside of your function.