I have this grab script here, and the part freezes in mid air when the position changes, When it should be falling.
Here is the script.
local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
local mouse = plr:GetMouse()
local campos = game:GetService("Workspace").CurrentCamera.CFrame.Position
local buttondown = false
local render = game:GetService("RunService")
local ts = game:GetService("TweenService")
local ti = TweenInfo.new(0.1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
--part.Position = (cf + cf.LookVector * 3).Position
wait(5)
mouse.Button1Down:Connect(function()
buttondown = true
end)
mouse.Button1Up:Connect(function()
buttondown = false
end)
function place(part)
local cf = CFrame.new(plr.Character.Head.Position, mouse.Hit.Position)
local t = ts:Create(part, ti, {CFrame =(cf + cf.LookVector * 5) })
t:Play()
--part.Position = (cf + cf.LookVector * 5).Position
end
render.Heartbeat:Connect(function()
if buttondown == true and mouse.Target then
if mouse.Target.Parent == workspace.parts then
local part = mouse.Target
place(part)
end
end
end)
I had this issue when making an item grab system for my game. When the player attempted to drop an item, it would just hang in the air like you example in the video.
The issue was that the item’s network ownership was the server, but I was moving the part through local scripts (the client).
The fix was to set the item’s network ownership to the player when they grabbed it. (In this case the item was a model, so I set the network ownership of the model’s primary part to the player)
Another solution was to apply a large enough force to the item after dropping it. I opted for the first solution.
I think it only works for some parts because the code hits an error: when you loop through the folder’s children, that also includes the script.
Scripts don’t have a function call :SetNetworkOwner(), so it errors, and the loop stops. Some parts probably got their network ownership set correctly, but then it broke when it reached the script object, leaving some part’s network ownership to not be set to the player.
To fix it, make sure the child you are indexing is a BasePart as so:
local plr = game:GetService("Players").PlayerAdded:Wait()
wait()
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("BasePart") then
v:SetNetworkOwner(player)
end
end
I tried, and the network ownership still shows up as black for some reason. I even tried looping it so it keeps resetting the ownership, but it doesn’t work.