More accurate projectile throwing

Im not quite sure on how to use linear velocity or line force. However this happened?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local damageEvent = ReplicatedStorage:WaitForChild("DamageEvent")
local throwToolEvent = ReplicatedStorage:WaitForChild("ThrowToolEvent")

throwToolEvent.OnServerEvent:Connect(function(player, targetPosition)
	local toolModel = ReplicatedStorage.Weapons:WaitForChild("Dodgeball")
	local thrownTool = toolModel:Clone()
	thrownTool.Parent = game.Workspace

	local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
	local handle = thrownTool:FindFirstChild("Handle")

	if handle then
		handle.Position = humanoidRootPart.Position + Vector3.new(1, 5, 0)

		local throwDirection = (targetPosition)

		local bodyForce = Instance.new("BodyForce")
		bodyForce.Force = throwDirection * 200
		bodyForce.Parent = handle

		local part = Instance.new("Part")
		part.Size = Vector3.new(2, 2, 2)
		part.Position = handle.Position + throwDirection * 1
		part.Anchored = true 
		part.CanCollide = false
		part.BrickColor = BrickColor.new("Bright red")
		part.Material = Enum.Material.Neon 
		part.Parent = game.Workspace 

		for _, part in ipairs(thrownTool:GetChildren()) do
			if part:IsA("BasePart") then
				part.CanCollide = true
			end
		end

		local function onTouch(otherPart)
			local character = otherPart.Parent
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			local otherPlayer = game.Players:GetPlayerFromCharacter(character)

			if humanoid and character.Name ~= player.Character.Name then
				local damageAmount = 15
				humanoid:TakeDamage(damageAmount)
				damageEvent:FireClient(player, damageAmount)
				thrownTool:Destroy()
			end
		end

		handle.Touched:Connect(onTouch)

		game.Debris:AddItem(thrownTool, 5)

		wait(0.1)
		bodyForce:Destroy()
	else
		warn("Handle not found in the tool model.")
	end
end)


Try this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local damageEvent = ReplicatedStorage:WaitForChild("DamageEvent")
local throwToolEvent = ReplicatedStorage:WaitForChild("ThrowToolEvent")

throwToolEvent.OnServerEvent:Connect(function(player, targetPosition)
	local toolModel = ReplicatedStorage.Weapons:WaitForChild("Dodgeball")
	local thrownTool = toolModel:Clone()
	thrownTool.Parent = game.Workspace

	local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
	local handle = thrownTool:FindFirstChild("Handle")

	if handle then
		handle.Position = humanoidRootPart.Position + Vector3.new(1, 5, 0)

		local throwDirection = (handle.Position - targetPosition).Unit
		
		local LinearVel = Instance.new("LinearVelocity")
		LinearVel.MaxForce = math.huge
		
		LinearVel.Attachment0 = handle:FindFirstChildOfClass("Attachment") do
			if not LinearVel.Attachment0 then
				local NewAttach = Instance.new("Attachment")
				NewAttach.Parent = handle
				
				LinearVel.Attachment0 = NewAttach
			end
		end
		LinearVel.VectorVelocity = throwDirection * 100

		local part = Instance.new("Part")
		part.Size = Vector3.new(2, 2, 2)
		part.Position = handle.Position + throwDirection * 1
		part.Anchored = true 
		part.CanCollide = false
		part.BrickColor = BrickColor.new("Bright red")
		part.Material = Enum.Material.Neon 
		part.Parent = game.Workspace 

		for _, part in ipairs(thrownTool:GetChildren()) do
			if part:IsA("BasePart") then
				part.CanCollide = true
			end
		end

		local function onTouch(otherPart)
			local character = otherPart.Parent
			local humanoid = character:FindFirstChildOfClass("Humanoid")
			local otherPlayer = game.Players:GetPlayerFromCharacter(character)

			if humanoid and character.Name ~= player.Character.Name then
				local damageAmount = 15
				humanoid:TakeDamage(damageAmount)
				damageEvent:FireClient(player, damageAmount)
				thrownTool:Destroy()
			end
		end

		handle.Touched:Connect(onTouch)

		game.Debris:AddItem(thrownTool, 5)
	else
		warn("Handle not found in the tool model.")
	end
end)

If it doesn’t work can you record a video showing its behaviour?

Make this number bigger and maybe you’ll see and effect

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.