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

Brick not moving?

Asked by 9 years ago

Hi, I am trying to create a hopperbin that when G is pressed, creates and slowly moves a brick to the mouse's Hit.X , Y, and Z position. Although, instead of doing what it is supposed to, it moves directly to the Hit position instead of slowly moving as though it is floating. Any solution to this?

The explorer is set up as shows: StarterPack-->HopperBin-->LocalScript

The Code:

local mouse = game.Players.LocalPlayer:GetMouse()

function DecimalRound(Number, DecimalPlaces)
local Int, Dec = math.modf(Number)
local DecSet = "1"..string.rep("0", DecimalPlaces)
local ToFakeInt = Dec * tonumber(DecSet)
local Convertion = math.floor(ToFakeInt)
local ToRealValue = Convertion / DecSet
local NewValue = Int + ToRealValue
return NewValue
end

mouse.KeyDown:connect(function(uKey)
    if uKey == "g" then
        local x = mouse.Hit.X
        local y = mouse.Hit.Y
        local z = mouse.Hit.Z
        local mX = nil
        local mY = nil
        local mZ = nil
        local xneg = false
        local yneg = false
        local zneg = false
        local tX = "Blank"
        local tY = "Blank"
        local tZ = "Blank"
        local timetook = 0


        local r = Instance.new("Part", game.Workspace)
        r.CFrame = CFrame.new(0, 5, 0)
        r.Anchored = true


        r.CanCollide = false
            if x < 0 then
                xneg = true
                tX = "true"
            else
                xneg = false
                tX = "false"
            end
            if y < 0 then
                yneg = true
                tY = "true"
            else
                yneg = false
                tY = "false"
            end
            if z < 0 then
                zneg = true
                tZ = "true"
            else
                zneg = false
                tZ = "false"
            end

            print("X: "..x.." "..tX)
            print("Y: "..y.." "..tY)
            print("Z: "..z.." "..tZ)
            repeat
                if xneg == false then
                    mX = DecimalRound(x, 2)
                    r.CFrame = CFrame.new(mX - 0.01, r.CFrame.y, r.CFrame.z)
                elseif xneg == true then
                    mX = DecimalRound(x, 2)
                    r.CFrame = CFrame.new(mX + 0.01, r.CFrame.y, r.CFrame.z)
                end

                if yneg == false then
                    mY = DecimalRound(y, 2)
                    r.CFrame = CFrame.new(r.CFrame.x, mY - 0.01, r.CFrame.z)
                elseif yneg == true then
                    mY = DecimalRound(x, 2)
                    r.CFrame = CFrame.new(r.CFrame.x, mY + 0.01, r.CFrame.z)
                end

                if zneg == false then
                    mZ = DecimalRound(z, 2)
                    r.CFrame = CFrame.new(r.CFrame.x, r.CFrame.y, mZ - 0.01)
                elseif zneg == true then
                    mZ = DecimalRound(z, 2)
                    r.CFrame = CFrame.new(r.CFrame.x, r.CFrame.y, mZ + 0.01)
                end
                wait(1)
            until
            r.CFrame.x == x and r.CFrame.y == y and r.CFrame.z == z

            if r.CFrame.x == x and r.CFrame.y == y and r.CFrame.z == z then
                print("done")
            end


    end
end)
0
Someone saw your question as "too broad" and downvoted you. I upvoted just to make up for that - don't worry, you will get an answer. Marios2 360 — 9y
0
Thanks! Again. disassembling 48 — 9y
0
The answer never came. User#11440 120 — 8y

Answer this question