Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Building tool part going through the floor?

(THIS IS A REPOST)

Hey, so I'm making a very basic btools system, and I need help where placing the object makes it go through the baseplate or other objects. Server

local tool = script.Parent

tool.PlaceObject.OnServerEvent:Connect(function(plr, pos)
	print("recieved msg")
	local block = Instance.new("Part")
	local health = Instance.new("IntValue")
	block.Size = Vector3.new(4,4,4)
	block.Anchored = true
	block.TopSurface = "Smooth"
	block.BottomSurface = "Smooth"
	block.Name = plr.Name.." Block"
	block.BrickColor = plr.TeamColor
	health.Name = "Health"
	health.Value = 3
	health.Parent = block
	block.Parent = workspace
	block.Position = pos
end)

Client

local plr = game.Players.LocalPlayer
local tool = script.Parent
local mouse = plr:GetMouse()

tool.Equipped:Connect(function()
	part = Instance.new("Part")
	part.Size = Vector3.new(4,4,4)
	part.Anchored = true
	part.CanCollide = false
	part.TopSurface = "Smooth"
	part.BottomSurface = "Smooth"
	part.Parent = workspace
	part.BrickColor = plr.TeamColor
	part.Transparency = .5
	mouse.TargetFilter = part
	
	mouse.Move:Connect(function()
		local mouseX = mouse.Hit.X
		local mouseY = mouse.Hit.Y
		local mouseZ = mouse.Hit.Z
		possiblePos = Vector3.new(math.floor(mouseX), math.floor(mouseY), math.floor(mouseZ))
		part.CFrame = CFrame.new(possiblePos)
	end)
	
	tool.Activated:Connect(function()
		local mouseX = mouse.Hit.X
		local mouseY = mouse.Hit.Y
		local mouseZ = mouse.Hit.Z
		tool.PlaceObject:FireServer(possiblePos)
	end)
end)

tool.Unequipped:Connect(function()
	part:Destroy()
end)

I'm experimenting with photos, so try this: https://lh3.googleusercontent.com/-Yq1yIgMoCb4/XsMUkfda2-I/AAAAAAAAFF0/O_Q0Crxkpponl4Cbj9ue6oMIBhEhom0dwCLcBGAsYHQ/s0/wack.png

Also, pos is mouse.Hit.p

Thanks!

5 comments

0

My only guess is that if you are placing the model inside baseplat it will spawn on the top of it, maybe? But you can try making the transparent brick look some studs above in the local, and pass the "pos" with less Y position if it stays in the air.

0

You could show your local script too

0

Alright, I'll get it..

0

Try disabling collisions (not on the part)

0

Collisions on what then..? I'm new to this stuff.

1 answer

Ok, I found a post on the devforum by Stickmasterluke and I used his template and made this script. It isn't the best in the world, but it works so that's all that matters xd

local player = game.Players.LocalPlayer
local tool = script.Parent
local mouse = player:GetMouse()
local RS = game:GetService("RunService")

local target = nil
local pos = nil
local norm = nil

local MAX_PLACEMENT_DISTANCE = 2000

function doFakeMouseStuff()
	local ignoreList = {part, player.Character}	--game.Workspace:WaitForChild("BaseStore"):GetChildren()
	local mouseRay = mouse.UnitRay
	local newRay = Ray.new(mouseRay.Origin, mouseRay.Direction.unit * MAX_PLACEMENT_DISTANCE)
	target, pos, norm = workspace:FindPartOnRayWithIgnoreList(newRay, ignoreList)
end

tool.Equipped:Connect(function()
	part = Instance.new("Part")
	part.Size = Vector3.new(4,4,4)
	part.Anchored = true
	part.CanCollide = false
	part.TopSurface = "Smooth"
	part.BottomSurface = "Smooth"
	part.Parent = workspace
	part.BrickColor = player.TeamColor
	part.Transparency = .5
	mouse.TargetFilter = part
	
	RS.RenderStepped:Connect(function()
		doFakeMouseStuff()
	end)
	
	mouse.Move:Connect(function()
		if part and pos and norm then
		doFakeMouseStuff()	-- Just to be cetain that the data is up to date.
		local endPos = pos + (norm * (part.Size*.5))
		part.CFrame = CFrame.new(math.floor(endPos.X), math.floor(endPos.Y), math.floor(endPos.Z))
	end
	end)
	
	tool.Activated:Connect(function()
		tool.PlaceObject:FireServer(part.Position)
	end)
end)

tool.Unequipped:Connect(function()
	part:Destroy()
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.