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

How do i make this placement system work better?

Asked by 3 years ago

So, basically i want the ClientStructure to move from stud to stud, but idk how. Here is the code if someone can tell me how i will be greatfull.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local UIS = game:GetService('UserInputService')
local RunService = game:GetService('RunService')
local placing = false
local yOrientation = 5



script.Parent.MouseButton1Click:Connect(function()
    if placing == false then
        placing = true
        local clientStructure = game.ReplicatedStorage.Structures.Wall:Clone()
        clientStructure.Material = 'Neon'
        clientStructure.BrickColor = BrickColor.new('Forest green')
        clientStructure.Parent = game.Workspace


        RunService.RenderStepped:connect(function()
            local mouseRay = mouse.UnitRay
            local myRay = Ray.new(mouseRay.Origin, mouseRay.Direction * 1000)
            local ignoreList = {game.Players.LocalPlayer.Character, clientStructure}
            local hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(myRay, ignoreList)
            if hit then
                local newAnglesCFrame = CFrame.Angles(0,math.rad(yOrientation), 0)
                local newCFrame = CFrame.new(pos.X, pos.Y + 2, pos.Z)
                clientStructure.CFrame = newCFrame * newAnglesCFrame


            end
        end)

        UIS.InputBegan:Connect(function(input, isTyping)
            if isTyping then return end
            if input.UserInputType == Enum.UserInputType.MouseButton1 then
                local clientStructureCFrame = clientStructure.CFrame
                game.ReplicatedStorage.PlaceStructure:FireServer(clientStructureCFrame)
            end
        end)

        UIS.InputBegan:Connect(function(input, isTyping)
            if isTyping then return end
            if input.KeyCode == Enum.KeyCode.R then
                yOrientation = yOrientation + 5
            end
        end)







    end
end)





Answer this question