Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

attempt to index field 'DriveSeat' (a nil value) HELP NEEDED ASAP?

I keep getting this error code i dont know what to do

while wait(3) do
    local player = game.Players.LocalPlayer
print("GOT THE NAME")
    local GoKart = player.name .. "'s GoKart"
print(GoKart)
    local Fuel = GoKart.DriveSeat.Fuel.Value
    script.Parent.Liters.Text = tostring(Fuel).."L"
end

Players.aleandroblingo.PlayerGui.Screen.Interface.Fule6: attempt to index field 'DriveSeat' (a nil value)22:21:13.55

1 answer

I like being honest. And I will be here.

This is wrong on so many levels.

It is good you tried, but unfortunately your script didn't work due to many reasons. I will try my best to help you fix it.

First, only LocalScripts can use LocalPlayer, because, well, they are local to a player. But since that wasn't the part that error'd, I'll assume this is a LocalScript.

Line 4. You are basically saying GoKart is a string. That's it. Not an object in Workspace, just a string. It error'd because GoKart is just a string, not an object with children. If you wanted it to find something in Workspace, do:

local GoKart = game:GetService("Workspace")[player.Name] .. "'s GoKart")--might error, I'm not a pro in string manipulation, just showing how to get the object in Workspace. I used the variable player in brackets because otherwise the game will think you are trying to find something named "player", not a variable that holds a value that you want to find in Workspace

Message to the community: If I'm wrong anywhere, feel free to correct me. Thanks :D

1 comment

0

its ok, it doesnt work

This discussion is preserved as it was. New answers, comments, and votes are closed.