Brick throw doesn't work properly

  1. What do you want to achieve?
    I want the brick to be thrown.

  2. What is the issue?
    The player won’t let go of the brick.

local db = false

local direction

local debris = game:GetService("Debris")

script.Parent.RemoteEvent.OnServerEvent:Connect(function(player, mousePos)
	direction = mousePos
end)

script.Parent.Activated:Connect(function()
	if not db then
		db = true
		
		--Play Animation--
		local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
		local throwAnim = humanoid:LoadAnimation(script.Throw)
		throwAnim:Play()
		
		wait(.5)
		
		--Throw the ball--
		script.Parent.Handle.Throw:Play()
		script.Parent.Handle.Transparency = 1
		local ball = game.ReplicatedStorage.Handle
		ball:Clone()
		
		ball.CFrame = CFrame.new(script.Parent.Handle.Position + script.Parent.Handle.CFrame.LookVector * 3, direction)
		
		--Trail--
		local attachment0 = Instance.new("Attachment", ball); attachment0.Position = Vector3.new(-.5,0,0); attachment0.Orientation = Vector3.new(0,180,0)
		local attachment1 = Instance.new("Attachment", ball); attachment1.Position = Vector3.new(.5,0,0); attachment1.Orientation = Vector3.new(0,0,0)
		local trail = Instance.new("Trail", ball); trail.Attachment0 = attachment0; trail.Attachment1 = attachment1
		
		--Body Velocity--
		local bv = Instance.new("BodyVelocity")
		bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		bv.P = 3000
		
		local ori = 0
		
		spawn(function()
			while wait() do
				ori = ori - .1
				ball.CFrame = ball.CFrame + ball.CFrame.lookVector * 4
				ball.Orientation = Vector3.new(ball.Orientation.X + ori, ball.Orientation.Y, ball.Orientation.Z)
			end
		end)
		
		--Touch Function--
		ball.Touched:Connect(function(hit)
			ball:Destroy()
			local player = game.Players:GetPlayersFromCharacter(hit.Parent)
			if player then
				local char = player.Character
				local humanoid = char:FindFirstChild("Humanoid")
				humanoid.Health = humanoid.Health - 20
				humanoid.PlatformStand = true
			end
			debris:AddItem(5)
		end)
		script.Parent.Handle.Transparency = 0
		wait(.5)
		db = false
	end
end)

I’ll assume there are no errors in output. Perhaps you could try using print debugging to check if certain things are firing or not. Is the animation playing? Does the brick move at all?

1 Like

Another thing you may want to consider is using ApplyImpulse…

1 Like

Yeah the output doesn’t say anything… The animation works including the sound! It’s just that if I aim at something, the brick is supposed to fly that direction but the brick doesn’t seem to ‘‘leave’’ the player…

Also, BodyVelocity is deprecated, use LinearVelocity instead.

Ohh yeah of course, I completely forgot about that oh my god, that might be the issue

1 Like

don’t worry, using deprecated stuff on accident happens way too often for me

Did it work? I’m curious to see if it was just the use of a deprecated object…

Oh sadly no, I’ve been trying to change it but doesn’t seem to be the issue

Oof, well, it’s still better to keep it though.

1 Like