Building system problem?

Basically, when you’re “previewing” a build the part hovers above the floor

I want the part that you’re previewing to be just on the floor, not clipping I want it to be just on the floor

As you can see, the part hovers above the ground instead of being directly on it.

Here is my script:

Client side:

-- services
local runservice = game:GetService("RunService")
local repstore = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local uis = game:GetService("UserInputService")
local tweenservice = game:GetService("TweenService")
local cas = game:GetService("ContextActionService")

-- stuff to do with the player
local char = script.Parent
local plr = players:GetPlayerFromCharacter(char)
local mouse = plr:GetMouse()
local camera = workspace.CurrentCamera
local gui = plr.PlayerGui.Cancel

-- stuff in replicatedstorage
local parts = repstore.Parts
local remoteevent = repstore.Place
local fail = repstore.Failed

-- deb
local deb = false

repstore.Other.OnClientEvent:Connect(function(part)
	if plr.Character.Stacked.Value > 1 then
		return
	end
	local part =  parts:FindFirstChild(part)
	if not part then
		warn("Client returned nil")
		return
	end

	gui.Enabled = true
	
	function preview()
		local clone = part:Clone()
		clone.Transparency = .5
		clone.CanQuery = false
		clone.CanCollide = false
		clone.Anchored = true
		clone.Parent = workspace.Previews
		return clone
	end

	local clone = preview()

	local param = RaycastParams.new()
	param:AddToFilter(script.Parent)

	function render()
		
		local location = uis:GetMouseLocation()
		local direction = camera:ViewportPointToRay(location.X, location.Y)
		local result = workspace:Raycast(direction.Origin, direction.Direction * 1000, param)
		if plr.Items:FindFirstChild(clone.Name) then
			if plr.Items:FindFirstChild(clone.Name).Value <=0 then
				clone:Destroy()
			end
		end
		if result and clone then
			clone.Position = result.Position + result.Normal * clone.Size.X/2
		end
	end

	runservice:BindToRenderStep("Preview", Enum.RenderPriority.Camera.Value, render)

	uis.InputBegan:Connect(function(input, grp)
		if grp then return end
		if  input.UserInputType == Enum.UserInputType.MouseButton1 then
			if clone and not deb then
				gui.Enabled = false
				remoteevent:FireServer(clone.CFrame, clone.Name)
			end
		elseif input.KeyCode == Enum.KeyCode.R then
			if clone then
				clone.Orientation += Vector3.new(0,90,0)
			end
		elseif input.KeyCode == Enum.KeyCode.T then
			if clone then
				clone.Orientation += Vector3.new(0,0,90)
			end
		end
	end)


end)

Server Side:

local repstore = game:GetService("ReplicatedStorage")
local remoteevent = repstore:WaitForChild("Place")
local parts = repstore.Parts

local rt = repstore.Gui


remoteevent.OnServerEvent:Connect(function(plr, cframe, item)

	if not item then
		warn("Item is nil, " .. plr .. " is likely hacking.")
		plr:Kick("Kicked for suspicious client behaviour: item requested is nil")
		return
	end
	--- remember to check if the player owns the item ty
	local obj = parts:FindFirstChild(item)
	if obj then
		if  plr.Items:FindFirstChild(obj.Name).Value <=0 then
			return
		end
		plr.Items:FindFirstChild(obj.Name).Value -=1
		local clone = obj:Clone()
		clone.CFrame = cframe
		clone.Parent = workspace
		local params = OverlapParams.new()
		params.FilterDescendantsInstances = {clone, workspace.Map.Baseplate, workspace.Map.SpawnLocation, workspace.Map.Part}
		params.FilterType = Enum.RaycastFilterType.Exclude
		local parts = workspace:GetPartBoundsInBox(clone.CFrame, clone.Size, params)
		plr.Character.Stacked.Value -=1
		print(plr.Character.Stacked.Value)
		if #parts > 0 then
			clone:Destroy()
			rt:FireClient(plr, "Failed")
			plr.Items:FindFirstChild(obj.Name).Value +=1
			--repstore.Fire:FireClient(plr, item)
			print("errr")
			plr.Character.Stacked.Value +=1
		end
	end
end)

clone.Position = result.Position + result.Normal * clone.Size.X/2

I believe it’s cuz ur multiplying it by clone.Size.X and not clone.Size.Y

2 Likes

Yeah I’m not sure why I didn’t try this, I thought I tried this before but I’m pretty sure I did clone.Position/2 instead so it didn’t work

Thank you

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