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

Click To Place Wall [Build Preview]?

Hi, I'm attempting to create a build preview. Many of you probably know what I'm talking about but just in case let me explain. This script is supposed to check and see if the player has enough resources to build the wall, then if they do, take away the required resources and place a transparent version of the wall that follows your mouse until you click to place it again. I have finally gotten it to follow the players mouse now but when you click it doesn't place it down. Clicking does nothing it just continues to follow the mouse. Can someone please help me?

GUI = script.Parent.Parent.Parent.Parent
Wall = game.ServerStorage.WoodWall
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()

script.Parent.MouseButton1Down:connect(function()
    if Player.leaderstats.Wood.Value >= 5 then
        Player.leaderstats.Wood.Value = Player.leaderstats.Wood.Value -5
        GUI.Visible = false
        WWall = Wall:Clone()
        WWall.Parent = game.Workspace
        WWall.Transparency = .5
    end
end)

Mouse.Move:connect(function()
    WWall.CFrame = CFrame.new(Mouse.Hit.p.x,1,Mouse.Hit.p.z)
    	Mouse.MouseButton1Down:Connect(function()
		WWall.Position = Mouse.Hit.p
		end)
end) 

2 comments

0

you are not defining a mouse click for the placing. you have the placing script in the shop gui or whatever script.Parent is, it seems, if thats not it, then you dont have a script to place it

0

Okay, I've edited the code above and it still doesn't place.

1 answer

✓ Accepted answer

You keep trying to use "WWall" although you only defined "Wall". Besides that, the reason that the part is never placed is because you never disconnect the functions that continuously move the part. Setting WWall.Position does not permanently set its position.

Here's a quick example of lego-esque building in a localscript. Not FE.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local blankPart = Instance.new('Part')
blankPart.Anchored=true
blankPart.CanCollide=false
blankPart.Transparency=0.75

while wait(0.5) do
	local part = blankPart:Clone() --never change the original part, only a clone
	part.Parent=workspace
	mouse.TargetFilter=part --ignore the clone while getting mouse position
	local moveConn
	moveConn = mouse.Move:connect(function()
		local p = mouse.Hit.p
		part.Position = Vector3.new(math.floor(p.X),math.ceil(p.Y),math.floor(p.Z)) --mouse position in whole numbers
	end)
	mouse.Button1Down:wait() --do not have to connect a click function :)
	moveConn:disconnect() --stop moving the clone
	part.CanCollide=true
	part.Transparency=0
end

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