#convert local to normal

13 messages · Page 1 of 1 (latest)

real marsh
#

need help converting local to normal script

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local grabbedPart = nil
local originalCFrame = nil
local originalColor = nil
local hoverRangeLimit = 5
local smoothness = 0.2
local throwVelocity = 50 -- Adjust this value to control the throwing speed
local ui1 = game.StarterGui.GrabGui.Frame.Q
local ui2 = game.StarterGui.GrabGui.Frame.Rmb
local function popout()
    ui1:TweenSize(UDim2.new(0, 200,0, 50), "InOut", "Back")
    ui2:TweenSize(UDim2.new(0, 200,0, 50), "InOut", "Back")
end

local function popin()
    ui1:TweenSize(UDim2.new(0, 0,0, 0), "InOut", "Back")
    ui2:TweenSize(UDim2.new(0, 0,0, 0), "InOut", "Back")
end
local function onGrab()
    if grabbedPart then
        return
    end

    local target = mouse.Target
    if target and target:IsA("BasePart") and not target:FindFirstAncestorWhichIsA("BodyMover") then
        local folder = target:FindFirstAncestor("CanPickup")
        if folder and folder:IsDescendantOf(workspace) then
            originalCFrame = target.CFrame
            grabbedPart = target
            grabbedPart.Anchored = true
            grabbedPart.Massless = true
            grabbedPart.Transparency = 0.5
            originalColor = grabbedPart.BrickColor

            -- Disable collision with other parts
            grabbedPart.CanCollide = false
            popout()
        end
    end
end
woeful moon
#

This isnt your script, is it?

real marsh
#
local function onRelease(input)
    if grabbedPart then
        if input.KeyCode == Enum.KeyCode.Q then
            grabbedPart.Anchored = false
            grabbedPart.Massless = false
            grabbedPart.Transparency = 0
            grabbedPart.Parent = workspace:FindFirstChild("CanPickup")
            popin()
            -- Enable collision with other parts
            grabbedPart.CanCollide = true
            local targetPosition = mouse.Hit.Position
            grabbedPart = nil
            originalCFrame = nil
            originalColor = nil
        elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
            local camera = workspace.CurrentCamera
            if camera then
                local throwDirection = (camera.CFrame.LookVector + Vector3.new(0, 0.5, 0)).Unit
                grabbedPart.Velocity = throwDirection * throwVelocity
            end

            grabbedPart.Anchored = false
            grabbedPart.Massless = false
            grabbedPart.Transparency = 0
            grabbedPart.Parent = workspace:FindFirstChild("CanPickup")

            -- Enable collision with other parts
            grabbedPart.CanCollide = true
            grabbedPart = nil
            originalCFrame = nil
            originalColor = nil
            popin()
        end
    end
end

local function moveGrabbedPart()
    if grabbedPart then
        local camera = workspace.CurrentCamera
        if camera then
            local targetCFrame = CFrame.new(camera.CFrame.Position + camera.CFrame.LookVector * hoverRangeLimit) * CFrame.Angles(math.pi/2, 0, 0)
            grabbedPart.CFrame = grabbedPart.CFrame:Lerp(targetCFrame, smoothness)
        end
    end
end
mouse.Button1Down:Connect(onGrab)
game:GetService("UserInputService").InputBegan:Connect(onRelease)
game:GetService("RunService").RenderStepped:Connect(moveGrabbedPart)
game:GetService("Players").PlayerAdded:Connect(popin)
#

and yea it is my script

#

i just dont know a easy way to convert to normal

woeful moon
#

Than how are you not able to "convert" to normal script AKA server side script?

real marsh
#

dunno

#

probs because of the local player

woeful moon
#

Just so you know... You would need a local script, a server script and a remote event

woeful moon
real marsh
#

so i get the on grab event on local and then start a remote

woeful moon
#

The issue is that you need to get the mouse position/actions, that why you would need a remote event to send to server from client

real marsh
#

and have the normal script do the movement