I have recently added a throwing mechanic to my game and basically whenever i go to throw it, most of the times it drops down while other times it actually gets thrown:
https://gyazo.com/618a55a0feb377fa6060de795574c770
I don’t know if this is server lag or an error with my script:
local function Throw()
grabbeditem.Velocity = camera.CFrame.LookVector * 150
end
The throw
mouse.Button2Up:Connect(function()
facing = false
grabbing = false
if grabbeditem and grabbeditem:FindFirstChild("BodyPosition") then
game.ReplicatedStorage.ItemReleased:FireServer(grabbeditem)
grabbeditem.Parent.Outline.Transparency = 1
grabbeditem.BodyPosition:Destroy()
end
if grabbeditem and grabbeditem:FindFirstChild("BodyGyro") then
grabbeditem.BodyGyro:Destroy()
end
Throw()
end)
What initiates the throw
local plr = game.Players.LocalPlayer
local char = plr.Character
local grabbing = false
local grabbeditem = nil
local facing = false
local dist = 11
local userinputservice = game:GetService('UserInputService')
local mouse = plr:GetMouse()
local camera = workspace.CurrentCamera
local highlightobject = nil
camera.FieldOfView = 90
repeat wait() until plr.Character
local function Throw()
grabbeditem.Velocity = camera.CFrame.LookVector * 150
end
mouse.Button1Down:Connect(function()
if mouse.Target and mouse.Target.Parent:IsA("Model") and mouse.Target.Parent:FindFirstChild("Grabbable") then
if not game.Players:FindFirstChild(mouse.Target.Parent.Name) and not mouse.Target.Parent.PrimaryPart:FindFirstChild("IsGrabbed") then
grabbing = true
grabbeditem = mouse.Target.Parent.PrimaryPart
game.ReplicatedStorage.ItemGrabbed:FireServer(grabbeditem)
local bp = Instance.new("BodyPosition", grabbeditem)
bp.D = 150
bp.P = 2000
grabbeditem.Parent.Outline.Transparency = 0
end
end
end)
mouse.Button2Down:Connect(function()
if grabbing == true then
facing = true
end
end)
mouse.Button2Up:Connect(function()
facing = false
grabbing = false
if grabbeditem and grabbeditem:FindFirstChild("BodyPosition") then
game.ReplicatedStorage.ItemReleased:FireServer(grabbeditem)
grabbeditem.Parent.Outline.Transparency = 1
grabbeditem.BodyPosition:Destroy()
end
if grabbeditem and grabbeditem:FindFirstChild("BodyGyro") then
grabbeditem.BodyGyro:Destroy()
end
Throw()
end)
mouse.Button1Up:Connect(function()
grabbing = false
facing = false
if grabbeditem and grabbeditem:FindFirstChild("BodyPosition") then
game.ReplicatedStorage.ItemReleased:FireServer(grabbeditem)
grabbeditem.Parent.Outline.Transparency = 1
grabbeditem.BodyPosition:Destroy()
end
if grabbeditem and grabbeditem:FindFirstChild("BodyGyro") then
grabbeditem.BodyGyro:Destroy()
end
end)
game:GetService("RunService").RenderStepped:Connect(function()
if grabbing == true and grabbeditem ~= nil then
if (plr.Character.PrimaryPart.Position - grabbeditem.Position).Magnitude < dist then
grabbeditem.BodyPosition.Position = ((camera.CFrame * CFrame.new(0,0,-(dist - 4))) ).Position
if facing == true then
grabbeditem.BodyPosition.Position = ((camera.CFrame * CFrame.new(2,1,-(dist - 8))) ).Position
end
else
grabbing = false
if grabbeditem and grabbeditem:FindFirstChild("BodyPosition") then
grabbeditem.BodyPosition:Destroy()
game.ReplicatedStorage.ItemReleased:FireServer(grabbeditem)
elseif grabbeditem and grabbeditem:FindFirstChild("BodyGyro") then
grabbeditem.BodyGyro:Destroy()
end
end
else
if mouse.Target ~= nil then
if mouse.Target.Parent:IsA("Model") then
if not game.Players:FindFirstChild(mouse.Target.Parent.Name) and mouse.Target.Parent:FindFirstChild("Grabbable") then
if (plr.Character.PrimaryPart.Position - mouse.Target.Parent.PrimaryPart.Position).Magnitude < dist * 1.2 and not mouse.Target.Parent.PrimaryPart:FindFirstChild("IsGrabbed") then
if highlightobject and mouse.Target ~= highlightobject then
highlightobject.Transparency = 1
end
highlightobject = mouse.Target.Parent.Outline
highlightobject.Transparency = 0
end
else
if highlightobject then
highlightobject.Transparency = 1
end
end
else
if highlightobject ~= nil then
highlightobject.Transparency = 1
end
end
end
end
end)
the full script