CurrentOwner is not a valid member of model tent how to fix?

I am making a house system I have a CurrentOwner a stringvalue placed in Plot1 under workspace
Screen Shot 2023-01-29 at 10.18.25 AM
Script in ServerScriptService

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Remotes = ReplicatedStorage.Remotes

local Events = Remotes.Events

local SpawnHouse = Events:WaitForChild("SpawnHouse")

local BuyHouse = Events:WaitForChild("BuyHouse")



--program--

BuyHouse.OnServerEvent:Connect(function(player, NameOfHouse, price)

	if player.Houses:FindFirstChild(NameOfHouse).Value == true then

		print("You Already Own This House!!")

	elseif player.Houses:FindFirstChild(NameOfHouse).Value == false and player.leaderstats.Money.Value >= price then

		player.Houses:FindFirstChild(NameOfHouse).Value = true

		player.leaderstats.Money.Value -= price

	end

	

end)



SpawnHouse.OnServerEvent:Connect(function(player, NameOfHouse)

	if player.Houses:FindFirstChild(NameOfHouse).Value == true and player.Plot.Value ~= "" then

		print("Hi!!")

		

		for i, house in pairs(game.Workspace:GetChildren()) do

			if house:IsA("Model") and house.Name == player.Name.."'sHouse" then

				house:Destroy()

			end

		end

		print("You have "..NameOfHouse.."!!")

		local House = ReplicatedStorage.Houses:FindFirstChild(NameOfHouse):Clone()

		print("clone")

		House.CurrentOwner.Value = player.Name

		print("can't see")

		House.Name = player.Character.Name.."'sHouse"

		House.Parent = game.Workspace

		print(game.Workspace:FindFirstChild(player.Plot.Value).CenterPos.Position)

		House:MoveTo(game.Workspace:FindFirstChild(player.Plot.Value).CenterPos.Position)

	end

end)

Between the prints that says clone and can’t see, that line of code when I click on the error in output brings me to it.
Error in output: CurrentOwner is not a valid member of model tent–House name tent btw
Tent is in a folder named Houses under ReplicatedStorage

1 Like

Is the house a child of the plot in the image or is it the model named plot in the image? You can try printing the house and clicking on the output to see where it leads you in the workspace and check if there is a child named CurrentOwner.

1 Like

Assuming that the hierarchy of model “Tent” follows similarly to Plot1–with CurrentOwner as a direct child of the model–it could be that your script is running before the StringValue is even loaded. See if this makes a difference:

House:WaitForChild("CurrentOwner").Value = player.Name
1 Like

I will try that and I think I forgot to mention that tent is in a folder under replicatedstorage. Folder name is Houses

It didn’t work And tent is in a folder (Houses) in Replicated storage

Houses is a folder in ReplicatedStorage and tent is in that folder forgot to mention

Could you send a screenshot of the hierarchy of the house folder and tent model?

1 Like

Of course!!

So I think the issue here is that there is no CurrentOwner value under the tent, and since that is what you’re referencing in your script as ‘House’, House.CurrentOwner won’t exist.

To fix this you either add a CurrentOwner value to the tent and any other houses you add in the future, or you keep track of the owner through the plot’s CurrentOwner value, which does exist as shown in your first image.

1 Like

How would I be able to keep track of the owner through the plot’s CurrentOwner value??

There are several ways to do this.

You can parent the house to the plot instead of the workspace, but this would interfere with the part of your script where you spawn a house, which loops through the workspace’s children to destroy any already existing houses. If you don’t want to change that there are some more solutions.

For example adding an object value inside of the house referencing the plot, or just adding a CurrentOwner value to the house might be easier. Although if you wish to avoid adding values into the house, you can also loop through each plot checking for a matching position with the player’s house. This would allow you to find the plot, and thereby the CurrentOwner value.

1 Like

Thank you so much for your help!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.