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)