WaitForChild not working with House Placement script

Hi!

Recently, Me and @vf9r have tried to make a House System.

We are finding an error in the WaitForChild.

What’s wrong?

(All scripts, error is probably in te first one)

local mod = game.ServerScriptService:WaitForChild("FurnitureMod")
local furniture = require(mod)
local plr = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()
local dragging = false

coroutine.wrap(function()
	
	while dragging == true do
		
		print(dragging)
		print("starting")
		
		while wait(.01) do
			furniture.drag(game.ReplicatedStorage.Furniture[script.Parent.Parent.Furniture.Value],mouse.Hit.p,plr)
			
		end
		
		
	end
	
end)

script.Parent.MouseButton1Click:Connect(function()
	
	dragging = true
	
	
end)
local template = script.Parent.ACard

for i,v in pairs(game.ReplicatedStorage.Furniture:GetChildren()) do
		
	local new = template:Clone()
	new.TextLabel.Text = v.Price.Value
	new.Furniture.Value = v.Name
	new.Parent = script.Parent
	
	wait()

	
end

template.BackgroundTransparency = 1
template.ImageButton.ImageTransparency = 1
template.TextLabel.TextTransparency = 1
local module = {}

function module.drag(model,cframe,plr)
	
	if model and cframe and plr then
		--//sanity check
		
		if plr.BuildMode.Value == true then
			
			local newModel = model:Clone()
			newModel.Parent = workspace
			
			for i,v in pairs(newModel:GetChildren()) do
				
				if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("TrussPart") or v:IsA("UnionOperation") or v:IsA("CornerWedgePart") then
					
					v.Transparency = .2
					--//set transparency for effect
					
				end
				
			end
			
			newModel:SetPrimaryPartCFrame(cframe)
			--//set the cframe
			
		end
		
	end
	
end

function module.place(model,cframe,plr)
	
	if model and cframe and plr then
		--//sanity check
		
		if plr.BuildMode.Value == true then
			
			model:SetPrimaryPartCFrame(cframe)
			--//set the cframe
			
			for i,v in pairs(model:GetChildren()) do
				
				if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("TrussPart") or v:IsA("UnionOperation") or v:IsA("CornerWedgePart") then
					
					v.Transparency = 0
					--//make sure the transparency is no longer .2 if was dragged
					
				end
				
			end
			
		end
		
	end
	
end

function module.chargeUser(model,plr)
	
	if model and plr then
		--//sanity check
		
		if plr.Flex_Points then
			
			plr.Flex_Points.Value = plr.Flex_Points.Value - model:FindFirstChild("Price").Value
			
		end
		
	end
	
end

return module

I think that’s it.

Thanks for any help supplied!

2 Likes

Update* If I remove WaitForChild, it says it doesn’t exist.
image

1 Like

I think the error is that you are referring to ServerScriptService which is empty for the client, this service is usable for server only.

1 Like

So, how would I get the Module?

1 Like

Move the module into ReplicatedStorage instead and get it from there.

I dont see the error anymore, but still wont work.

1 Like

Oops! Looks like you aren’t using any remotes to handle the placement of furnitures. You would try to visually apply the selections only on client while the server will listen for an attempt of placing something somewhere. That said, you should use a remote that listens for client’s call of placing any thing and that’s where you should sanitize input, not on client.

Apart from this little issue, I probably have to undergo a longer debugging session.

1 Like

So we need to redo all of this to work with Remotes? I dont really like them, that’s why I used a module.

1 Like

That’s not how server-client model works. You can’t use a module to manipulate the server, remotes are necessary. Modules act as the main script; if it was required by a client script, it would not be able to access across the client-server boundaries.

2 Likes