I am trying to make an object that you can throw, and also stuns people on its hit. However, whenever you throw it, it just vanishes and does not do anything. Someone please help!
The script that Stuns
function onTouch(hit)
if hit.Parent ~= nil and hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Torso") then
character = hit.Parent
if character.Torso:FindFirstChild("Knock") == nil then
character.Torso.CFrame = character.Torso.CFrame * CFrame.Angles(math.rad(180),0,0)
knock = Instance.new("BodyThrust")
knock.Name = "Knock"
knock.force = Vector3.new(0,0,10000)
knock.Parent = character.Torso
game:GetService("Debris"):AddItem(knock, 1)
character.Humanoid.Sit = false
end
end
end
script.Parent.Touched:connect(onTouch)
The script that throws
sp=script.Parent
loaded=false
local g=sp.Handle:Clone()
function fire(v)
sp.Parent.Torso["Right Shoulder"].MaxVelocity=0.7
sp.Parent.Torso["Right Shoulder"].DesiredAngle=3.6
wait(.1)
sp.Parent.Torso["Right Shoulder"].MaxVelocity=1
sp.Handle.Transparency=1
sp.Handle.Fire:play()
local vCharacter=sp.Parent
local vPlayer=game.Players:playerFromCharacter(vCharacter)
local head=vCharacter:findFirstChild("Head")
if head==nil then return end
local launch=head.Position+10*v
local missile=g:clone()
missile.CFrame=CFrame.new(launch,launch+v)
missile.Velocity=v*50
local force=Instance.new("BodyForce")
force.force=Vector3.new(0,240,0)
force.Parent=missile
local ps = script.Parent.BangScript:Clone()
ps.Parent = missile
missile.BangScript.Disabled = false
local creator_tag = Instance.new("ObjectValue")
creator_tag.Value = vCharacter
creator_tag.Name = "creator"
creator_tag.Parent = missile
missile.Parent = game.Workspace
end
sp.Enabled=true
function onActivated()
if not sp.Enabled then
return
end
sp.Enabled=false
local character=sp.Parent;
local humanoid=character.Humanoid
if humanoid==nil then
print("Humanoid not found")
return
end
if loaded then
loaded=false
local targetPos=humanoid.TargetPoint
local lookAt=(targetPos-character.Head.Position).unit
fire(lookAt)
wait(7.5)
sp.Enabled=true
elseif not loaded then
sp.Parent.Torso["Right Shoulder"].MaxVelocity=0.6
sp.Parent.Torso["Right Shoulder"].DesiredAngle=-3.6
wait(.1)
sp.Handle.Transparency=0
wait(.1)
loaded=true
end
sp.Enabled=true
end
script.Parent.Activated:connect(onActivated)
Thanks for reading :)
