I was making a game from a tutorial and I copied and checked everything exactly as it should have been. However, when I played the game, this error message appeared:
ServerScriptService.Script:17: attempt to index nil with 'Value'
It said that the problem was this line:
return game.ServerStorage.Cars:FindFirstChild(NameOfCar.Price.Value)
This is the code that was inside the script.
Does anyone know how to fix this?
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
local folder = leaderstats
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local cash = Instance.new("IntValue")
cash.Name = "Cash"
local currencyName = cash.Name
cash.Value = 40000
cash.Parent = leaderstats
end)
game.ReplicatedStorage:WaitForChild("CheckPrice").OnServerInvoke = function(player,NameOfCar)
**return game.ServerStorage.Cars:FindFirstChild(NameOfCar.Price.Value)
**
end
game.ReplicatedStorage:WaitForChild("SpawnCar").OnServerEvent:Connect(function(player, NameOfCar)
local car = game.ServerStorage.Cars:FindFirstChild(NameOfCar):Clone()
car:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame + Vector3.new(0,0,15))
car.Parent = workspace
car:MakeJoints()
car.Name = player.Name.."'s ".."NameOfCar"
end)

2 comments
Thank you. Let me try that (:
Thanks. It worked!