ServerScriptService.Script:14: attempt to index nil with 'Price'?

Hello! I am making a boat shop and have been having this error, I do not know how to fix it so I came here.

I have has this error for the past 2 days [ServerScriptService.Script:14:

Screenshot_26

I tried all yesterday to find a solution to no prevail.

The script below is the problem

	
>>>This line is the issue	return game.ServerStorage.Boats:FindFirstChild(NameOfBoat).Price.Value
	
end


game.ReplicatedStorage:WaitForChild("SpawnBoat").OnServerEvent:Connect(function(player, NameOfBoat)
	local boat = game.ServerStorage.Boats:FindFirstChild(NameOfBoat):Clone()
boat:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame + Vector3.new(3, 10, -9))
boat.Parent = workspace
boat:MakeJoints()
boat.Name = player.Name.."'s ".. NameOfBoat
end)

If anybody knows what the problem is please let me know!
1 Like

Can you use ``` to insert your code as I’d be able to read it better please. I can’t see price anywhere on that, so can you screenshot the error and give us the whole code and script name.

2 Likes

Sure one moment please…

1 Like

Finished…

1 Like

Can you also show me all of the script as NameOfBoat must be defined somewhere else.

1 Like
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local gold = Instance.new("IntValue")
	gold.Name = "Gold"
	gold.Value = 1000
	gold.Parent = leaderstats
end)

game.ReplicatedStorage:WaitForChild("CheckPrice").OnServerInvoke = function(player,NameOfBoat)
	
		return game.ServerStorage.Boats:FindFirstChild(NameOfBoat).Price.Value
	
end


game.ReplicatedStorage:WaitForChild("SpawnBoat").OnServerEvent:Connect(function(player, NameOfBoat)
	local boat = game.ServerStorage.Boats:FindFirstChild(NameOfBoat):Clone()
boat:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame + Vector3.new(3, 10, -9))
boat.Parent = workspace
boat:MakeJoints()
boat.Name = player.Name.."'s ".. NameOfBoat
end)
1 Like

Okay well NameOfBoat must be somewhere else on another script too, can you show me where NameOfBoat first comes from entirely.

1 Like

I was using a guide and nowhere in the script is it defined.

1 Like

Then what is the value NameOfBoat on line 12 in the function.

It is the name of the boat in question. There is a Boats folder in ServerStorage and NameOfBoat defines the name of the boat that I am targeting inside that folder.

Could you send the line where you local the NameOfBoat?

He doesn’t it’s called in from a function as an event from ServerStorage I think.

There isnt one. I will relook trhough the original guide to see if it was ever defined

If that’s the case then he needs to use speech marks for it to work.

I’ll try that…

If there isn’t one, then that’s the thing that’s erroring.

I don’t know how to define that…

Could you send the other LocalScript where you fire the BindableEvent?

	
	if script.Parent.Parent.Purchased == true then
		--Spawn It
		game.ReplicatedStorage.SpawnBoat:FireServer(script.Parent.Parent.Name)
		else 
	--Let the player buy the item
		local PriceOfItem = game.ReplicatedStorage:WaitForChild("CheckPrice"):InvokeServer(script.Parent.Parent.Name)
		
		if game.Players.LocalPlayer.leaderstats.Gold.Value >= PriceOfItem and script.Parent.Parent.Purchased.Value == false then
			-- The player has enough gold
			game.Players.LocalPlayer.leaderstats.Gold.Value = game.Players.LocalPlayer.leaderstats.Gold.Value - PriceOfItem
			script.Parent.Parent.Purchased.Value = true
		end
end
end)

FindFirstChild(whatever) does not always return a result. You have to store it in a variable and check it for nil first.