I am making a game in which you have to escape each level by picking up, throwing and dropping parts.
My middle click (throwing) function isn't working. The part isn't moving at all, and I'm not sure if the click is registering. Am I using the input wrong? Please help.
Oh, and here's the code.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local uis = game:GetService("UserInputService")
local pack = player:WaitForChild("Backpack")
local character = player.Character
mouse.Icon = "rbxassetid://3248591495"
mouse.Button1Down:Connect(function()
if mouse.Target ~= nil then
if mouse.Target.Locked == false then
mouse.Target.Name = "Handle"
local tool = Instance.new("Tool", pack)
tool.CanBeDropped = false
tool.TextureId = "rbxassetid://3248571585"
mouse.Target.Parent = tool
end
end
end)
mouse.Button2Down:Connect(function()
if character.Tool ~= nil then
character.Tool.Handle.CanCollide = true
character.Tool.Handle.Position = mouse.Hit.p
character.Tool.Handle.Parent = workspace
character.Tool:Destroy()
end
end)
if uis:IsMouseButtonPressed(Enum.UserInputType.MouseButton3) == true then
if character.Tool ~= nil then
character.Tool.Handle.CanCollide = true
character.Tool.Handle.Parent = workspace
character.Tool.Handle.CFrame = CFrame.new(character.Tool.Handle.Position, mouse.Hit.p)
character.Tool.Handle.Velocity = character.Tool.Handle.CFrame.LookVector * 5
character.Tool:Destroy()
end
end
uis.InputBegan:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.ButtonR2 then
if mouse.Target ~= nil then
if mouse.Target.Locked == false then
mouse.Target.Name = "Handle"
local tool = Instance.new("Tool", pack)
tool.CanBeDropped = false
tool.TextureId = "rbxassetid://3248571585"
mouse.Target.Parent = tool
end
end
end
if input.KeyCode == Enum.KeyCode.ButtonL2 then
if character.Tool ~= nil then
character.Tool.Handle.CanCollide = true
character.Tool.Handle.Position = mouse.Hit.p
character.Tool.Handle.Parent = workspace
character.Tool:Destroy()
end
end
end)

2 comments
Your code won't even compile. GetMouse is not deprecated or removed. Stop spreading false information. https://developer.roblox.com/api-reference/function/Player/GetMouse
guess what pidgey? I tried this and it WORKS. Im sorry, you were right