I am making a house system I have a CurrentOwner a stringvalue placed in Plot1 under workspace
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
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.
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:
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.
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.