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

Why do i always get Workspace.Script:8: attempt to index field 'Value' (a nil value)?

I made a button that spawns a car. But when i press it, i always get Workspace.Script:8: attempt to index field 'Value' (a nil value). The value inside the player is full (objectvalue). It has something in it, but it still says that.

script:

game.ReplicatedStorage:WaitForChild("SpawnCar").OnServerEvent:Connect(function(player)
	for i,v in pairs(game.Workspace:GetChildren()) do
		if v.Name == player.Name.."'s Car" then
			v:Destroy()
		end
	end
	wait(0.1)
	local car = player:WaitForChild("SelectedCar").Value:Clone()
	car:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame + Vector3.new(0,0,15))
	car.Parent = game.Workspace
	car:MakeJoints()
	car.Name = player.Name.."'s Car"
end)

thanks for helping!

2 comments

0

How are you creating the ObjectValue?

0

PlayerAdded. Added a wait.

1 answer

You can't clone a Value. Try cloning the object instead.

game.ReplicatedStorage:WaitForChild("SpawnCar").OnServerEvent:Connect(function(player)
    for i,v in pairs(game.Workspace:GetChildren()) do
        if v.Name == player.Name.."'s Car" then
            v:Destroy()
        end
    end
    wait(0.1)
    local car = player:WaitForChild("SelectedCar"):Clone() -- Delete the ".Value"
    car:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame + Vector3.new(0,0,15))
    car.Parent = game.Workspace
    car:MakeJoints()
    car.Name = player.Name.."'s Car"
end)

Hope it works!

2 comments

0

That means im cloning the value right? im trying to clone the value inside it.

0

You can't clone a value. It is impossible. If you want to clone the object, do what is below. If you want to set a variable as the value do local value = player:WaitForChild("SelectedCar").Value

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