this code.
local tool = script.Parent
local remote = tool:WaitForChild("wawa")
remote.OnServerInvoke = function(player, pos)
local handle = tool:FindFirstChild("Handle")
if not handle then return end
local clone = handle:Clone()
clone.Anchored = false
clone.CanCollide = true
clone.Parent = workspace
clone.CFrame = handle.CFrame
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = (pos - handle.Position).Unit * 100
bodyVelocity.MaxForce = Vector3.new(1e9, 1e9, 1e9)
bodyVelocity.Parent = clone
game:GetService("Debris"):AddItem(clone, 5)
end
and this code.
local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local remote = tool:WaitForChild("wawa")
tool.Activated:Connect(function()
local hit = mouse.Hit
if hit then
remote:InvokeServer(hit.Position)
end
end)
take reference of this code.
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local tool = script.Parent
local throwEvent = tool:WaitForChild("ThrowEvent")
local handle = tool:WaitForChild("Handle")
local THROW_SPEED = 125
local COOLDOWN = 1
local MIN_VELOCITY = 1
local UNATTACH_DELAY = 2
local STAB_SOUND_ID = 6276679056
local FACE_ID = "http://www.roblox.com/asset/?id=127638835452481"
local PICKUP_COOLDOWN = 0.5
local weldReference
local attachedToModel
local thrown = false
local throwOwner
local canUnattach = false
local isGrabbed = false
local gyroReference
local gyroConn
local canPickup = true
local pickupCooldown = false
local particle = Instance.new("ParticleEmitter")
particle.Name = "gush"
particle.LightInfluence = 1
particle.Lifetime = NumberRange.new(2,2)
particle.SpreadAngle = Vector2.new(-90,90)
particle.LockedToPart = false
particle.WindAffectsDrag = true
particle.VelocitySpread = -90
particle.Speed = NumberRange.new(10,10)
particle.Size = NumberSequence.new(0.25)
particle.Acceleration = Vector3.new(0,-25,0)
particle.ZOffset = 1
particle.VelocityInheritance = 1
particle.Rate = 0
particle.Texture = "rbxassetid://12075813308"
particle.RotSpeed = NumberRange.new(-360,360)
particle.Shape = Enum.ParticleEmitterShape.Sphere
particle.Parent = handle
local function playSound(id,parent)
local sound = Instance.new("Sound",parent)
sound.SoundId = "rbxassetid://"..id
sound:Play()
sound.Ended:Connect(function() sound:Destroy() end)
end
local function changeFace(humanoid)
local head = humanoid.Parent:FindFirstChild("Head")
if not head then return end
local face = head:FindFirstChild("face")
if face and face:IsA("Decal") then
face.Texture = FACE_ID
end
end
local function applyRagdollR15(char)
local humanoid = char:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
for _,motor in ipairs(char:GetDescendants()) do
if motor:IsA("Motor6D") then
local a0 = Instance.new("Attachment",motor.Part0)
a0.CFrame = motor.C0
local a1 = Instance.new("Attachment",motor.Part1)
a1.CFrame = motor.C1
local bs = Instance.new("BallSocketConstraint",motor.Part0)
bs.Attachment0 = a0
bs.Attachment1 = a1
bs.LimitsEnabled = true
bs.TwistLimitsEnabled = true
bs.TwistLowerAngle = -45
bs.TwistUpperAngle = 45
motor.Enabled = false
end
end
end
local function applyRagdollR6(char)
local torso = char:FindFirstChild("Torso") or char:FindFirstChild("UpperTorso")
if not torso then return end
local size = torso.Size
local offsets = {
Head = {off0=Vector3.new(0,size.Y/2,0),off1=Vector3.new(0,-char.Head.Size.Y/2,0)},
["Right Arm"] = {off0=Vector3.new(size.X/2,size.Y*0.25,0),off1=Vector3.new(-char["Right Arm"].Size.X/2,char["Right Arm"].Size.Y/2,0)},
["Left Arm"] = {off0=Vector3.new(-size.X/2,size.Y*0.25,0),off1=Vector3.new(char["Left Arm"].Size.X/2,char["Left Arm"].Size.Y/2,0)},
["Right Leg"] = {off0=Vector3.new(size.X*0.25,-size.Y/2,0),off1=Vector3.new(0,char["Right Leg"].Size.Y/2,0)},
["Left Leg"] = {off0=Vector3.new(-size.X*0.25,-size.Y/2,0),off1=Vector3.new(0,char["Left Leg"].Size.Y/2,0)}
}
for partName,data in pairs(offsets) do
local part = char:FindFirstChild(partName)
if part then
local a0 = Instance.new("Attachment",torso)
a0.CFrame = CFrame.new(data.off0)
local a1 = Instance.new("Attachment",part)
a1.CFrame = CFrame.new(data.off1)
local bs = Instance.new("BallSocketConstraint",torso)
bs.Attachment0 = a0
bs.Attachment1 = a1
bs.LimitsEnabled = true
bs.TwistLimitsEnabled = true
bs.TwistLowerAngle = -45
bs.TwistUpperAngle = 45
end
end
for _,jointName in ipairs({"Neck","Left Shoulder","Right Shoulder","Left Hip","Right Hip"}) do
local joint = torso:FindFirstChild(jointName)
if joint then joint:Destroy() end
end
end
local function applyRagdoll(char)
local humanoid = char:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
if humanoid.RigType == Enum.HumanoidRigType.R15 then
applyRagdollR15(char)
else
applyRagdollR6(char)
end
humanoid.PlatformStand = true
humanoid.AutoRotate = false
end
local function dealDamage(hit,partName)
local model = hit:FindFirstAncestorWhichIsA("Model")
if not model then return end
local humanoid = model:FindFirstChildOfClass("Humanoid")
if not humanoid or humanoid.Health<=0 then return end
if partName=="Head" then
humanoid.Health = 0
changeFace(humanoid)
applyRagdoll(model)
else
humanoid:TakeDamage(math.random(15,40))
if humanoid.Health<=0 then
changeFace(humanoid)
applyRagdoll(model)
end
end
end
local function resetAttachments()
if weldReference then weldReference:Destroy(); weldReference=nil end
if gyroReference then gyroReference:Destroy(); gyroReference=nil end
if gyroConn then gyroConn:Disconnect(); gyroConn=nil end
attachedToModel=nil
thrown=false
throwOwner=nil
canUnattach=false
isGrabbed=false
end
local function enablePickup()
canPickup=true
pickupCooldown=false
end
local function disablePickup()
canPickup=false
end
local function setupSpearPartTouched(part)
part.Touched:Connect(function(hit)
if not hit or not hit.Parent then return end
if attachedToModel or not thrown then return end
if throwOwner and hit:IsDescendantOf(throwOwner.Character) then return end
local model = hit:FindFirstAncestorWhichIsA("Model")
local humanoid = model and model:FindFirstChildOfClass("Humanoid")
if not humanoid then
thrown=false
disablePickup()
task.delay(PICKUP_COOLDOWN,enablePickup)
return
end
local hitPos,partPos = hit.Position,part.Position
local dir = (partPos-hitPos).Unit
local offset = dir*(hit.Size.Magnitude/3)
local preserved = part.CFrame-part.Position
part.CFrame = CFrame.new(hitPos+offset)*preserved
weldReference = Instance.new("WeldConstraint",part)
weldReference.Part0 = part
weldReference.Part1 = hit
attachedToModel = model
canUnattach = false
disablePickup()
dealDamage(hit,hit.Name)
if humanoid.Health>0 then
task.delay(UNATTACH_DELAY,function()
canUnattach=true
enablePickup()
end)
end
particle:Emit(50)
playSound(STAB_SOUND_ID,part)
end)
end
for _,part in ipairs(tool:GetDescendants()) do
if part:IsA("BasePart") and part~=handle then
setupSpearPartTouched(part)
end
end
tool.CanBeDropped = false
local function onPlayerTouch(player)
if not canPickup or pickupCooldown then return end
if not player:IsA("Player") then return end
if not player.Character then return end
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
if humanoid:GetState()==Enum.HumanoidStateType.Running or humanoid:GetState()==Enum.HumanoidStateType.RunningNoPhysics then
tool.Parent = player.Character
resetAttachments()
enablePickup()
end
end
handle.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then onPlayerTouch(player) end
end)
tool.Equipped:Connect(function()
isGrabbed=true
resetAttachments()
enablePickup()
end)
tool.Unequipped:Connect(function()
isGrabbed=false
end)
tool.AncestryChanged:Connect(function(_,parent)
if parent and parent:IsA("Model") and parent:FindFirstChildOfClass("Humanoid") then
if weldReference then resetAttachments() end
end
end)
throwEvent.OnServerEvent:Connect(function(player)
local char = player.Character
if not char or tool.Parent~=char or not handle then return end
resetAttachments()
thrown=true
throwOwner=player
tool.Parent=workspace
handle.Anchored=false
handle.CanCollide=true
handle:SetNetworkOwner(nil)
disablePickup()
local humanoidRootPart = char:WaitForChild("HumanoidRootPart")
handle.CFrame = humanoidRootPart.CFrame * CFrame.Angles(0,math.rad(90),0) * CFrame.new(6,1,0)
handle.CustomPhysicalProperties = PhysicalProperties.new(1,0.5,0.2,1,1)
local lookVector = char.Head.CFrame.LookVector
local horizontalDirection = Vector3.new(lookVector.X,0,lookVector.Z).Unit
handle:ApplyImpulse((horizontalDirection*THROW_SPEED+Vector3.new(0,5.25,0))*handle.AssemblyMass)
local velocityCheck
velocityCheck = RunService.Heartbeat:Connect(function()
if handle and handle.AssemblyLinearVelocity.Magnitude<=MIN_VELOCITY then
thrown=false
velocityCheck:Disconnect()
task.delay(PICKUP_COOLDOWN,enablePickup)
end
end)
end)
tool.Activated:Connect(function()
if attachedToModel and canUnattach and isGrabbed then
local attachPart = weldReference and weldReference.Part1 or handle
resetAttachments()
tool.Parent = throwOwner and throwOwner.Character or workspace
particle.Parent = attachPart
particle:Emit(50)
particle.Parent = handle
end
end)
it's supposed to be like a spear. with deflect and other stuff like that.