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

What does this mean? Expected identifier when parsing expression, got 'local'

Asked by 4 years ago
Edited 4 years ago

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)
0
try just removing 'local' from line 1 Leamir 3138 — 4y
0
When I did that, there was an error under getPlayerFromPart iiNiqhtTime 5 — 4y
0
what error is it? You could check if its a valid character on line 4.I think the error is just because part.Parent isn't a valid character  Leamir 3138 — 4y
0
Is this the full script, it seems like its an error above this function. moo1210 587 — 4y
0
I think i got it now, i think this was due to 'objectsFolder' not being defined oof iiNiqhtTime 5 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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.

Ad
Log in to vote
0
Answered by 4 years ago

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.

Answer this question