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

How do I make a working rotate system for my custom build/stamp tool?

Asked by 9 years ago

I am making my own build/stamp tool. Everything works fine except the rotate system (or code.) Here is the code:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local enabled = false
local modelname = ""

for n, v in pairs (script.Parent.BuildFrame:GetChildren()) do
    v.MouseButton1Click:connect(function()
        if player.Character ~= nil then
            if enabled == false then
                enabled = true
                local model = game.ServerStorage:FindFirstChild(v.Name):Clone()
                model.PrimaryPart = model.PrPart
                model.Parent = game.Workspace.CurrentCamera
                mouse.TargetFilter = model
                modelname = model.Name
                script.Parent.Parent.BuildNote:TweenPosition(UDim2.new(0, 0, 1, -50), "Out", "Sine", 0.5, false, nil)
                while game:GetService("RunService").RenderStepped do
                    repeat wait() until mouse.Target ~= nil
                    if player.Character.Humanoid.Health ~= 0 then
                        model:SetPrimaryPartCFrame(CFrame.new(mouse.Hit.x, 1.1, mouse.Hit.z) * CFrame.Angles(script.Value.Value))
                    end
                end
            end
        end
    end)
end

mouse.KeyDown:connect(function(key)
    if key:lower() == "q" then
        game.Workspace.CurrentCamera:FindFirstChild(modelname):destroy()
        script.Parent.Parent.BuildNote:TweenPosition(UDim2.new(0, 0, 1, 0), "Out", "Sine", 0.5, false, nil)
        modelname = ""
        enabled = false
    elseif key:lower() == "r" then
        script.Value.Value = "0, 1/2 * math.pi, 0"
        wait(3)
        print(script.Value.Value)
    end
end)

mouse.Button1Down:connect(function()
    if enabled == true then
        local model = game.ServerStorage:FindFirstChild(modelname):Clone()
        model.Parent = game.Workspace
        game.Workspace.CurrentCamera:FindFirstChild(modelname):destroy()
        model:MoveTo(Vector3.new(mouse.Hit.x, 1.1, mouse.Hit.z))
        enabled = false
    end
end)

Here is the output:

14:00:47.068 - Players.Player.PlayerGui.GameInterface.Menu.BuildScript:20: bad argument #3 to 'Angles' (number expected, got no value) 14:00:47.069 - Script 'Players.Player.PlayerGui.GameInterface.Menu.BuildScript', Line 20 14:00:47.070 - Stack End

The "Value" is a StringValue, by the way. Thanks.

Answer this question