So, I’m having trouble with a script. Not sure what’s causing it.
The image is referring to this line:
local housemodel = replicatedstorage.HouseModels:FindFirstChild(item).House:Clone()
Simply said, the RemoteEvent includes the name of the item that’s supposed to replace the previous house, deletes the old and spawns in a new one.
Code:
replicatedstorage = game:GetService("ReplicatedStorage")
local catalogstuff = replicatedstorage.Houses
local assets = replicatedstorage.HouseModels
local x
local y
local z
local userplot
script.Parent.OnServerEvent:connect(function(player,item)
--find the currently-equipped item
for i,v in pairs(player.EquippedHouse:GetChildren()) do
v:Destroy()
end
--replace the item
for i,v in pairs(catalogstuff:GetChildren()) do
if v.Name == item then
local item = v:Clone()
item.Parent = player.EquippedHouse
--remove existing house
for i,v in pairs (game.Workspace.HousePlot:GetChildren()) do
if v.Owner.Value == player.Name then
v.Plot.House:Destroy()
--place the new one
local housemodel = replicatedstorage.HouseModels:FindFirstChild(item).House:Clone()
housemodel.Parent = v.Plot
--move house
housemodel:SetPrimaryPartCFrame(v.Plot.CFrame)
print("Moved house")
--get land orientation
x = v.Plot.Orientation.X
y = v.Plot.Orientation.Y
z = v.Plot.Orientation.Z
--rotate house
housemodel.PrimaryPart.Orientation = Vector3.new(x, y, z)
print("Rotated house to match the land")
end
end
end
end
end)
Best regards.