I keep getting this error and I have 0 ideas why. Workspace..Homebuilder:13: attempt to perform arithmetic on field 'NumberOfBuildings' (a userdata value)

This is my script:

local HomeStatus = script.Parent.Stats:FindFirstChild("Home")
local Wood = script.Parent.Stock:FindFirstChild("Wood")

while true do
	wait(1)
	if HomeStatus.Value == "Homeless" and Wood.Value >=9 then
		HomeStatus.Value = "HasAHome"
		local model = game.ServerStorage.Buildings["Small Medieval House 2"]:Clone()
		model.Parent = game.Workspace
		local cf = CFrame.new(script.Parent.Torso.Position)
		model:SetPrimaryPartCFrame(cf)
		Wood.Value = Wood.Value - 10
		workspace.GlobalStats.NumberOfBuildings.Value = workspace.GlobalStats.NumberOfBuildings + 1
		model.Name = workspace.GlobalStats.NumberOfBuildings.Value
	end
end

3 comments

0

NumberOfBuildings.Value, you forgot the .Value, so the game thinks you're trying to add 1 to an object. This is why it's causing a userdata value error. | workspace.GlobalStats.NumberOfBuildings.Value = workspace.GlobalStats.NumberOfBuildings.Value + 1

0

I'm such an idiot, thank you.

0

Np