So I have a placement script which currently sort of works. When the green Play button is pressed in testing, a 'preview' of a model follows the mouse of the player. When the player clicks the mouse button, the model is cloned into the workspace and the 'preview' is destroyed.
local rs = game:WaitForChild("ReplicatedStorage")
local placeablePart = rs:WaitForChild("PlaceableParts")
local model = script.SelectedPart.Value
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local runService = game:GetService("RunService")
local cloneModel = model:clone()
cloneModel.Parent = game.Workspace
local modelCFrame = cloneModel:GetModelCFrame()
mouse.TargetFilter = cloneModel
function roundAToB(a,b)
return(math.floor((a/b)+0.5)*b)
end
local modelPreview, modelPlace
modelPreview = runService.RenderStepped:connect(function()
local hit = mouse.Hit.p
cloneModel:SetPrimaryPartCFrame(CFrame.new(roundAToB(hit.X,4),1.5,roundAToB(hit.Z,4)) * CFrame.Angles(0,0,math.rad(0)))
end)
modelPlace = mouse.Button1Down:connect(function()
local new = cloneModel:clone()
new.Parent = workspace
modelPreview:Disconnect()
modelPlace:Disconnect()
cloneModel:Destroy()
end)
Currently it starts as soon as the play button is pressed, I need this to only start if a GUI button is pressed, but so that the player can press the button again and the code still works.
Right now I am using :Disconnect() to stop the 'preview' model, but this may be wrong for what I need to do.
Any help is appreciated. Thanks in advance!
