I’m trying to throw a basketball tool, but it flings me instead:
local UserInputService = game:GetService("UserInputService")
local applyImpulseOnBallRemote = game:GetService("ReplicatedStorage")["Apply Impulse on ball"]
local camera = workspace.CurrentCamera
local tool = script.Parent
local toolHandle = tool:FindFirstChild("Handle")
local params = RaycastParams.new()
params.FilterDescendantsInstances = {} -- anything you want, for example the player's character, the ray filters through these
params.FilterType = Enum.RaycastFilterType.Exclude -- choose exclude or include
local function rayResult(x, y)
local unitRay = camera:ViewportPointToRay(x, y) -- :ViewportPointToRay() is another choice
return workspace:Raycast(unitRay.Origin, unitRay.Direction * 500, params) -- 500 is how far to raycast
end
tool.Activated:Connect(function()
local mouse = UserInputService:GetMouseLocation()
local result = rayResult(mouse.X, mouse.Y)
if result then
print(result.Instance, result.Position)
tool.Parent = workspace
toolHandle.AssemblyLinearVelocity = result.Position * toolHandle.AssemblyMass * 120
applyImpulseOnBallRemote:FireServer(tool, result) -- On the server
end
end)