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

Attempt to index local 'location' (a nil value)?

Asked by 5 years ago
Edited 5 years ago

```lua function module.teleport(plr, location) local registered = split(script.Registered.Value, ",")

local exists = false

for _,i in pairs(registered) do
    if exists ~= true then
        exists = i == location
    end
end

print(exists)

if exists then
    location = registered[location]
    local position

    if location:IsA("BasePart") then
        position = location.Position
    else
        error("Models are not supported as a viable LocationPart. Use a BasePart instead.")
        return
    end

    if plr:IsA("Model") and plr.Parent == workspace and game.Players:FindFirstChild(plr.Name) then
        plr:MoveTo(position)
    else
        error("You did not provide a valid object. Valid objects must be a child of game.Workspace, must be a model, and must have a counterpart in game.Players.")
        return
    end

else
    error("LocationPart \""..location.."\" does not exist.")
    return
end

end ```

This code keeps giving an error and I just can't seem to find out the issue: ``` true

15:03:24.186 - ServerScriptService.TeleService:47: attempt to index local 'location' (a nil value) 15:03:24.187 - Stack Begin 15:03:24.187 - Script 'ServerScriptService.TeleService', Line 47 - field teleport 15:03:24.188 - Script 'ServerScriptService.TeleService', Line 74 15:03:24.188 - Stack End ```

0
maybe put location = exists Gameplayer365247v2 1055 — 5y
0
why? exists states that location, well, *exists*. Location needs to be an object. VikingCatto 15 — 5y
0
can you shows us where you defined location? The first time  AnonymousDeveloper13 22 — 5y
0
it's defined as a paramterer VikingCatto 15 — 5y

Answer this question