All the post I’ve recently are slowly coming together, and now I just need to know how could I make a lumber tycoon drag system that could work with models/parts without seperate scripts. I’ve looked at some post’s on the devforum are outdated or just different for what I want. If you find a non outdated post reply, or if u know how to make it tell me.
I’ve had issues like if i grab and i want it to be in the air and I point the part into the sky it just goes away into the void. And I would like to know how to make it have physics not like frozen. Thanks!
This is what im currently working with
local uis = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local att1
local att2
local sphere
local align
uis.InputBegan:Connect(function(int)
if int.UserInputType == Enum.UserInputType.MouseButton1 then
sphere = Instance.new("Part")
sphere.Shape = Enum.PartType.Ball
sphere.Anchored = true
att1 = Instance.new("Attachment")
att2 = Instance.new("Attachment")
align = Instance.new("AlignPosition")
align.Attachment1 = att1
align.Attachment0 = att2
sphere.CanCollide = false
sphere.Transparency = 0.7
sphere.CanQuery =false
sphere.Parent = workspace
att1.Parent = sphere
align.ApplyAtCenterOfMass = true
end
end)
uis.InputEnded:Connect(function(int)
if int.UserInputType == Enum.UserInputType.MouseButton1 then
sphere:Destroy()
end
end)
local function raycast()
local mouse = uis:GetMouseLocation()
local raycast1 = camera:ViewportPointToRay(mouse.X, mouse.Y)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
local ovParams = OverlapParams.new() --this creates a blank OverlapParams thing
ovParams.FilterDescendantsInstances = {}
ovParams.CollisionGroup = "Default"
ovParams.FilterType = Enum.RaycastFilterType.Whitelist
ovParams.MaxParts = 1
local raycast2 = workspace:Raycast(raycast1.Origin, raycast1.Direction * 50, params, ovParams)
return raycast2
end
renderser.RenderStepped:Connect(function()
local result = raycast()
if sphere then
if result and result.Instance then
local x = result.Position.X
local y = result.Position.Y
local z = result.Position.Z
sphere.Position = Vector3.new(x,y,z)
if result.Instance:FindFirstChild("Drag") then
att2.Parent = result.Instance
align.Parent = result.Instance
end
end
end
end)```
You can limit the range via Clipping, so your player cannot move a part further from them than a given maxDistance. playerPosition is assumed to be the player’s position.
local targetPos = result.Position
local direction = (targetPos - playerPosition).Unit
local distance = (targetPos - playerPosition).Magnitude
local limitedDistance = math.min(distance, maxDistance)
sphere.Position = direction * limitedDistance
I could try this but I quite don’t know where to put it in the script.
local result = raycast()
if sphere then
if result and result.Instance then
local targetPos = result.Position
local direction = (targetPos - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Unit
local distance = (targetPos - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).Magnitude
local limitedDistance = math.min(distance, 50)
sphere.Position = direction * limitedDistance
if result.Instance:FindFirstChild("Drag") then
att2.Parent = result.Instance
align.Parent = result.Instance
part = result.Instance
part.CanCollide = false
part.CanQuery = false
end
end
end
end)```
This just does not work, it creates a sphere and the sphere just teleports away
Hey, I got it working by using workspace.CurrentCamera.CFrame.Position(game.Players.LocalPlayer:GetMouse().Hit.Position - camera.CFrame.Position).Unit * 20 This can look better but i was in a hurry.