Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Click To Place Wall [Build Preview]?

Asked by 8 years ago
Edited 8 years ago

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?

01GUI = script.Parent.Parent.Parent.Parent
02Wall = game.ServerStorage.WoodWall
03Player = game.Players.LocalPlayer
04Mouse = Player:GetMouse()
05 
06script.Parent.MouseButton1Down:connect(function()
07    if Player.leaderstats.Wood.Value >= 5 then
08        Player.leaderstats.Wood.Value = Player.leaderstats.Wood.Value -5
09        GUI.Visible = false
10        WWall = Wall:Clone()
11        WWall.Parent = game.Workspace
12        WWall.Transparency = .5
13    end
14end)
15 
View all 21 lines...
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 RobloxianDestory 262 — 8y
0
Okay, I've edited the code above and it still doesn't place. austin10111213 28 — 8y

1 answer

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
8 years ago

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.

01local player = game.Players.LocalPlayer
02local mouse = player:GetMouse()
03local blankPart = Instance.new('Part')
04blankPart.Anchored=true
05blankPart.CanCollide=false
06blankPart.Transparency=0.75
07 
08while wait(0.5) do
09    local part = blankPart:Clone() --never change the original part, only a clone
10    part.Parent=workspace
11    mouse.TargetFilter=part --ignore the clone while getting mouse position
12    local moveConn
13    moveConn = mouse.Move:connect(function()
14        local p = mouse.Hit.p
15        part.Position = Vector3.new(math.floor(p.X),math.ceil(p.Y),math.floor(p.Z)) --mouse position in whole numbers
View all 21 lines...
Ad

Answer this question