Throwing and returning system issue

When the player throws the item in the first time it works perfectly but then after doing it again it bugs out and the player is thrown with the item some times

here is the script

Replicated_Storage.Shield_ServerSide.Remotes.Throw.OnServerEvent:Connect(function(Player)
	
	wait(0.4)
	
	Recieved = false
	local Shield  = Player.Character:WaitForChild("Shield")
	Shield.Parent = workspace
	Shield.Motor6D.Enabled= false
	Shield.CanCollide = true
	
	local BV = Instance.new("BodyVelocity",Shield)
	BV.MaxForce = Vector3.new(1000,1000,1000)
	local PlayerD = Player.Character:WaitForChild("HumanoidRootPart").CFrame.LookVector
	BV.Velocity = PlayerD*100
	Shield.Orientation = Vector3.new(90,0,0)
	Shield.Orientation = Vector3.new(90,0,0)
	Shield.Orientation = Vector3.new(90,0,0)
	Shield.Touched:Connect(function(Hit)
		if Hit.Parent.Name~= Player.Name then
			local a = Instance.new("Sound",Shield)
	a.SoundId = script.Crash.SoundId
	a:Play()
			r = true
			Shield.CanCollide = false
			Shield.Orientation = Vector3.new(90,0,0)
			Shield.Anchored = true
			local tweens = game:GetService("TweenService")
			local Inf = TweenInfo.new(1)
			BV.MaxForce = Vector3.new(0,0,0)
			
			Shield.Touched:Connect(function(a)
				if a.Parent == Player.Character and Recieved == false then
				
					Recieved = true
					r = false
					BV:Destroy()
					Shield.Parent = Player.Character
					Shield.Anchored = false
					Shield.Motor6D.Enabled = true
					Shield.CanCollide = false
					Replicated_Storage.Shield_ServerSide.Remotes.Throw:FireClient(Player)
				end
			end)
			while r == true do
				wait(0.1)
				local tween = tweens:Create(Shield,Inf,{Position = Player.Character.HumanoidRootPart.Position})

				tween:Play()
				if r == false then
					break
				end
			end
			
			Shield.Orientation = Vector3.new(90,0,0)
		end
		
	end)
end)
1 Like

Probably because it’s colliding with the player, use collision groups or set the item to CanCollide false

1 Like

At which part of the script? The first touched function or the second.

Shield.CanCollide = false

Try this.

It didn’t work.

aaaaaaaaaaaaaaaaaaaaaaaaaaaaa

1 Like

Also I’ve noticed that the position where the shield is thrown is changed and that after the third time the player won’t be able to throw it

1 Like

I’ve managed to fix it by restarting the script every time it ends

1 Like

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