so i’ve been trying to make a item where you can throw. The only thing bad about this is it doesn’t really have a cap speed of how fast or far it can go. I know this most likely has something to do with ray casting, but I’m not good at ray casting and I have no idea how I would set this up. Since its using mouse position, the higher the number is, the further and faster it goes leaving no actual limit for it
Local script:
local players = game:GetService("Players")
local player = players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
local remote = tool:WaitForChild("RemoteEvent")
remote.OnClientEvent:Connect(function()
remote:FireServer(mouse.Hit.Position)
end)
script:
local players = game:GetService("Players")
local tool = script.Parent
local handle = tool.Handle
local remote = tool.RemoteEvent
tool.Activated:Connect(function()
if not tool.Enabled then return end
tool.Enabled = false
local character = tool.Parent
local player = players:GetPlayerFromCharacter(character)
if player then
remote:FireClient(player)
end
end)
remote.OnServerEvent:Connect(function(player, mousePosition)
local direction = (mousePosition - handle.Position)
local force = direction * 2 + Vector3.new(0, workspace.Gravity / 4, 0)
handle.AssemblyLinearVelocity = force
tool.Parent = workspace
end)
Thanks in advance!