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!
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!