Knife hit error

Hi, I designed a knife for my game, but when the knife touches the person, it does 99% damage instead of killing them, which means I have to kill that person over and over again. Now I will give you the commands and let me know if there is anything I need to fix.

  1. Knife
    damage = 100
    swingrate = 0.9

anims={“GenericStab1”,“GenericStab2”,“StabPunch”,“Backstab”}
lastAnim = “”
bloodeffects = true

ready = false
equipped = false
lastswing = 0

local storage = script.Parent:WaitForChild(“Storage”)
local down = storage:WaitForChild(“MouseDown”)
local debris = game:GetService(“Debris”)
local state = script.Parent:WaitForChild(“SetState”)
local throw = script.Parent:WaitForChild(“RequestThrow”)
local animEvent = script.Parent:WaitForChild(“PlayAnimation”)
local soundEvent = script.Parent:WaitForChild(“PlayClientSound”)

function WaitFor(start,…)
local obj = start
for _,v in pairs{…} do
obj = obj:WaitForChild(v)
end
return obj
end

local player

while not player do
if script.Parent.Parent:IsA(“Model”) then
player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
elseif script.Parent.Parent:IsA(“Backpack”) then
player = script.Parent.Parent.Parent
end
end

function runsound(id,volume)
local volume = volume or 1
local sound = Instance.new(“Sound”)
sound.Looped = false
sound.Pitch = 1
sound.SoundId = “http://www.roblox.com/asset/?id=”…tostring(id)
sound.PlayOnRemove = false
sound.Volume = volume
debris:AddItem(sound,3)
sound.Parent = script.Parent.Handle
wait()
sound:Play()
end

function runAnimation(anim)
if anim == “Backstab” then
Spawn(function ()
script.Parent.GripUp = Vector3.new(0,-1,0)
wait(.55)
script.Parent.GripUp = Vector3.new(0,1,0)
end)
end
animEvent:FireAllClients(anim)
end

function clientSound(ref)
soundEvent:FireAllClients(ref)
end

b = Instance.new(“Part”)
b.BrickColor = BrickColor.new(“Bright red”)
b.formFactor = “Custom”
b.CanCollide = false
b.TopSurface = “Smooth”
b.BottomSurface = “Smooth”

function makeblood(part)
local bin = script.Parent.Parent:findFirstChild(“BloodBin”) or Instance.new(“Model”,script.Parent.Parent)
bin.Name = “BloodBin”
local function r(a,b)
– This is basically math.random with floats instead of integers.
a = a or 0; b = b or 1
return a+(b-a)math.random()
end
if part then
local bl = b:clone()
bl.Transparency = r()
.5
bl.Size = Vector3.new(.2r(1,5),.2,.2r(1,5))
bl.Velocity = part.Velocity+(Vector3.new((r()-.5),(r()-.5),(r()-.5))30)
bl.RotVelocity = part.RotVelocity+(Vector3.new((r()-.5),(r()-.5),(r()-.5))20)
bl.CFrame = part.CFrame
CFrame.new((r()-.5)3,(r()-.5)3,(r()-.5)3)CFrame.Angles(math.pi2r(),math.pi2r(),math.pi
2*r())
bl.Parent = workspace
end
end

didHit = false
swinging = false

function ThrowAttack(_,target)
script.Parent.Enabled = false
script.Parent.Handle.Throw:Play()
wait(0.2)
local Handle = script.Parent.Handle
local Humanoid = script.Parent.Parent:findFirstChild(“Humanoid”)
local touchedConn
local throwingHandle
if Humanoid then
Handle.Archivable = true
throwingHandle = Handle:Clone()
throwingHandle.Name = “ThrownKnife”
throwingHandle.Transparency = 0
script.ThrowSmoke:clone().Parent = throwingHandle
game:GetService(“Debris”):AddItem(throwingHandle, 5)
throwingHandle.Parent = Humanoid.Parent
throwingHandle.Velocity = (target - throwingHandle.CFrame.p).unit * 200
throwingHandle.CFrame = CFrame.new(throwingHandle.CFrame.p, throwingHandle.CFrame.p + throwingHandle.Velocity) * CFrame.Angles(0, 0, math.rad(-90))
local floatingForce = Instance.new(‘BodyForce’, throwingHandle)
floatingForce.force = Vector3.new(0, 196.2 * throwingHandle:GetMass(), 0)
local spin = Instance.new(‘BodyAngularVelocity’, throwingHandle)
spin.angularvelocity = throwingHandle.CFrame:vectorToWorldSpace(Vector3.new(0, -400, 0))
end
wait(0.08)
if throwingHandle then
throwingHandle.CanCollide = true
Handle.Transparency = 1
touchedConn = throwingHandle.Touched:connect(function (hit)
if hit.Transparency == 1 then return end
if hit.Name == “Handle” then return end
if hit.Parent == Humanoid.Parent then return end
if hit.Parent:findFirstChild(“Humanoid”) == nil then return end
if throwingHandle.Transparency ~= 0 then return end
hit.Parent.Humanoid:TakeDamage(damage)
delay(3,function ()
(throwing) = false
script.Parent.Enabled = true
Handle.Transparency = 0
end)
clientSound(“Critical”)
throwingHandle.Anchored = true
for i = 1,10 do
throwingHandle.Transparency = i*.1
wait()
end
throwingHandle:Destroy()
touchedConn:disconnect()
end)
end
local proceed = true
for i = 1,80 do
if script.Parent.Enabled then
proceed = false
elseif proceed then
wait()
end
end
Handle.Transparency = 0
script.Parent.Enabled = true
throwing = false
end

function closestPlayerInSight(characters)
local torso = script.Parent.Parent:findFirstChild(“Torso”)
if torso then
local closestTorso,closestDist = nil,math.huge
for _,v in pairs(characters) do
local dist = (v.Torso.Position-torso.Position).magnitude
if dist <= 8 and dist < closestDist then
closestTorso = v.Torso
closestDist = dist
end
end
if closestTorso and closestDist then
return closestTorso.Parent
end
end
end

function Activate()
if equipped and (tick()-lastswing)>=swingrate and ready and script.Parent.Enabled and script.Parent.Handle.Transparency == 0 and script.Parent.Parent:findFirstChild(“Head”) then
script.Parent.Enabled = false
didHit = false
newanim = anims[math.random(1,#anims)]
runAnimation(newanim)
lastAnim = newanim
lastswing = tick()
swinging = true
local characters = {}
for _,v in pairs(game.Players:GetPlayers()) do
if v ~= player then
if v.Character and v.Character:findFirstChild(“Torso”) and v.Character:findFirstChild(“Humanoid”) and v.Character.Humanoid.Health > 0 then
table.insert(characters,v.Character)
end
end
end
for _,v in pairs(workspace:GetChildren()) do
if v:IsA(“Model”) and v:findFirstChild(“Humanoid”) and v.Humanoid.Health > 0 and v ~= script.Parent.Parent then
table.insert(characters,v)
end
end
for i = 1,6 do
if not didHit then
local userToKill = closestPlayerInSight(characters)
if userToKill then
userToKill.Humanoid:TakeDamage(damage)
didHit = true
clientSound(lastAnim == “Backstab” and “Critical” or “Normal”)
local numbloodeffects = lastAnim == “Backstab” and math.random(100,150) or math.random(20,40)
for i = 1,math.random(numbloodeffects-1,numbloodeffects+1) do
makeblood(userToKill.Torso)
end
end
end
wait(0.05)
end
if not didHit then – If we didn’t hit a player immediately, then play a swing sound to the server
script.Parent.Handle.Swing:Play()
end
swinging = false
didHit = false
wait(0.6)
script.Parent.Enabled = true
if down.Value then
Activate()
end
end
end

down.Changed:connect(function()
if down.Value then
Activate()
end
end)

hu = nil

script.Parent.Equipped:connect(function ()
ready = true
equipped = true
script.Parent.Handle.Transparency = 0
hu = script.Parent.Parent:findFirstChild(“Humanoid”)
if hu then
hu.WalkSpeed = 20
end
if down.Value then
Activate()
end
end)

state.OnServerEvent:connect(function (player,b)
down.Value = b
end)

throw.OnServerEvent:connect(ThrowAttack)

script.Parent.Unequipped:connect(function ()
down.Value = false
if hu then
hu.WalkSpeed = 20
hu = nil
end
ready = false
equipped = false
end)

  1. Knife Script

local parent = script.Parent
local Handle = parent:WaitForChild(“Handle”)
local Creator = parent:WaitForChild(“Creator”)
CanDmg = false
Can = true
parent.Equipped:Connect(function()
Handle.Equip:Play()
if Creator.Value == nil then
Creator.Value = parent.Parent end
end)
parent.Unequipped:Connect(function()
Handle.UnEquip:Play()
end)
repeat wait() until Creator.Value ~= nil
parent.Activated:Connect(function()
if Handle.Transparency == 1 then return end
function slash()
print(“hip”)
local creator = Creator.Value
local Animations = parent:WaitForChild(“Animations”)
local AnimChild = Animations:GetChildren()
local AnimRad = math.random(1,#AnimChild)
local AnimSel = AnimChild[AnimRad]
local AP = creator:WaitForChild(“Humanoid”):LoadAnimation(AnimSel)
if Can == true then
Can = false
AP:Play()
wait(0.15)
CanDmg = true
Handle.Swing:Play()
Handle.SlashTrail.Enabled = true
wait(0.25)
CanDmg = false
Handle.SlashTrail.Enabled = false
wait(0.06)
Can = true
end
end
slash()
end)
function on(t)
local h = t.Parent:FindFirstChildOfClass(“Humanoid”)
if h ~= nil and CanDmg == true then
CanDmg = false
local cre = Creator.Value
h:TakeDamage(parent.Dmg.Value)
Handle.Swing:Stop()
Handle.Hit:Play()
if h.Health>0 then
if not h:FindFirstChild(“creator”) then
local ov = Instance.new(“ObjectValue”,h)
ov.Name = “creator”
ov.Value = game.Players:WaitForChild(cre.Name)
else
local ovs = h:GetChildren()
for i = 1,#ovs do
if (ovs[i].Name == “creator”) then
ovs[i].Value = game.Players:WaitForChild(cre.Name) end
end
end
end
end
end
Handle.Touched:Connect(on)

  1. Local Knife

local storage = script.Parent:WaitForChild(“Storage”)
local down = storage:WaitForChild(“MouseDown”)
local runanim = storage:WaitForChild(“RunAnim”)
local cs = script.Parent:WaitForChild(“PlayClientSound”)
local state = script.Parent:WaitForChild(“SetState”)
local throw = script.Parent:WaitForChild(“RequestThrow”)
local animEvent = script.Parent:WaitForChild(“PlayAnimation”)

animspeed = 1
equipspeed = 1.5
throwing = false

function WaitForChildren(start,…)
if not start:IsA(“Instance”) then return end
local currentObj = start
for _,v in pairs{…} do
if type(v) == “string” then
currentObj = currentObj:WaitForChild(v)
end
end
return currentObj
end

function update(mouse)
if mouse ~= nil then
mouse.Icon = script.Parent.Enabled and “rbxasset://textures\GunCursor.png” or “rbxasset://textures\GunWaitCursor.png”
end
end

heatStorage = {}

local hitSound
local input = game:GetService(“UserInputService”)
local isMobile = input.TouchEnabled

function ClientThrow(target)
– I’m doing this to remove the lag factor of the knife from the client’s perspective
– This knife doesn’t actually do anything to the players, its basically simulating what the server is doing
– Worse case scenario: Accuracy and latency screw it up
local Handle = script.Parent.Handle
local serverKnife = script.Parent.Parent:WaitForChild(“ThrownKnife”)
local clientKnife = Handle:Clone()
clientKnife.Transparency = 0
clientKnife.CanCollide = false
game:GetService(“Debris”):AddItem(clientKnife, 5)
clientKnife.Parent = workspace.CurrentCamera
clientKnife.Velocity = (target - clientKnife.CFrame.p).unit * 200
clientKnife.CFrame = serverKnife.CFrame
local floatingForce = Instance.new(‘BodyForce’, clientKnife)
floatingForce.force = Vector3.new(0, 196.2 * clientKnife:GetMass(), 0)
local spin = Instance.new(‘BodyAngularVelocity’, clientKnife)
spin.angularvelocity = clientKnife.CFrame:vectorToWorldSpace(Vector3.new(0, -400, 0))
serverKnife.Changed:connect(function (property)
if property == “Anchored” then
clientKnife.Anchored = true
clientKnife.CFrame = serverKnife.CFrame
for i = 1,10 do
clientKnife.Transparency = i*.1
wait()
end
clientKnife:Destroy()
end
end)
end

function runAnimation(an)
local h = game.Players.LocalPlayer.Character:findFirstChild(“Humanoid”)
local anim = storage:findFirstChild(an)
if anim and h then
local theanim = h:LoadAnimation(anim)
if theanim and h.Health > -100 then
theanim:Play(nil,nil,animspeed)
if anim.Name == “Backstab” then
script.Parent.GripUp = Vector3.new(0,-1,0)
wait(.75)
script.Parent.GripUp = Vector3.new(0,1,0)
end
delay(1,function ()
theanim:Stop()
end)
end
end
end

animEvent.OnClientEvent:connect(runAnimation)

throwing = false

function setKnifeState(b)
b = throwing and false or b
state:FireServer(b)
end

function requestThrow()
if script.Parent.Handle.Transparency == 0 and not throwing and script.Parent.Enabled then
throwing = true
runAnimation(“Throw”)
local hit = game.Players.LocalPlayer.Character.Humanoid.TargetPoint
throw:FireServer(hit)
ClientThrow(hit)
wait(3)
throwing = false
end
end

function Equipped(mouse)
hitSound = game.Players.LocalPlayer.PlayerGui:findFirstChild(“Sound”) or Instance.new(“Sound”)
hitSound.SoundId = “http://www.roblox.com/asset/?ID=186311262
hitSound.Parent = game.Players.LocalPlayer.PlayerGui
for _,v in pairs(game.Players:GetPlayers()) do
if v.Character and v.Character.Humanoid.Health > 0 and v.Character:findFirstChild(“Torso”) and v.Character ~= game.Players.LocalPlayer.Character then
local heat = storage.Heat:clone()
heat.Parent = game.Players.LocalPlayer.PlayerGui
heat.Adornee = v.Character.Torso
heat.Enabled = true
table.insert(heatStorage,heat)
v.Character.Humanoid.Died:connect(function ()
heat:Destroy()
end)
heat.Adornee.Changed:connect(function ()
if not heat.Adornee or heat.Adornee.Parent == nil then
heat:Destroy()
end
end)
heat.Changed:connect(function ()
if not heat.Adornee then
heat:Destroy()
end
local scale = math.sqrt(heat.AbsoluteSize.X^2+heat.AbsoluteSize.Y^2)
heat.ImageLabel.Visible = scale > 30
end)
end
end
local input = game:GetService(“UserInputService”)
mouse.Button1Down:connect(function ()
setKnifeState(true)
end)
mouse.Button1Up:connect(function ()
setKnifeState(false)
end)
mouse.Button2Down:connect(function ()
requestThrow()
end)
input.TouchTap:connect(function ()
setKnifeState(true)
wait(.2)
setKnifeState(false)
end)
input.TouchLongPress:connect(function ()
requestThrow()
end)
mouse.Icon = script.Parent.Enabled and “rbxasset://textures/GunCursor.png” or “rbxasset://textures/GunWaitCursor.png”
script.Parent.Changed:connect(function ()
mouse.Icon = script.Parent.Enabled and “rbxasset://textures/GunCursor.png” or “rbxasset://textures/GunWaitCursor.png”
end)
end

function Unequipped()
for _,v in pairs(heatStorage) do
v:Destroy()
end
heatStorage = {}
if hitSound then
hitSound:Destroy()
end
end

script.Parent.Equipped:connect(Equipped)
script.Parent.Unequipped:connect(Unequipped)

cs.OnClientEvent:connect(function (value)
if hitSound then
hitSound.SoundId = (value == “Normal”) and “http://www.roblox.com/asset/?ID=186311262” or “http://www.roblox.com/asset/?ID=186311262
hitSound.Pitch = 1,0 +(math.random()/1)
hitSound:Play()
end
end)

7 Likes

Try setting the damage to something like 110.

3 Likes

Ok I will try this but for which command 1 or 2 or 3 or all of them?

2 Likes

Not sure what you mean, just set the damage variable to 110

damage = 110
1 Like

I think I explained it wrong. For example, there are 3 different commands such as local knife, Knife, Knife, Commands, I have listed above, you can find the 1,2 and 3 versions above. Where exactly should I put this command in the command?

1 Like

Knife 1 I’m guessing, it’s hard to see without proper formatting

1 Like

I will try this command knife 1, but if I put your command at the bottom, will it cause any problems?

1 Like

I’m assuming it won’t, but you can try it yourself.

I will try now and reply back in 10 minutes.

Unfortunately, it didn’t help much, I did 110, I did 200, but it still didn’t work, do you have any other suggestions?

Would it be possible for you to link a file for us to download and check out? One that preferably has just the knife and its scripts in it. This way we can properly analyse it and see where everything is meant to go. By doing this, we’ll be able to fix it quicker.

I’m sorry, I don’t fully understand, when you say the command, should I write the command in the file or should I send the objects inside the knife with a screen excerpt?

I mean a file such as this:

example.rbxl (43.7 KB)

In order to publish us a link to a downloadable file for this you have to go to

File > Save to Roblox as > Create new

and then name it whetever you like, once you’ve done that you must link it here by pressing the “upload” button here

image_2024-06-08_141417027

and then finding the file location

2 Likes

Please format your code properly using ```. It’s very hard to read. :slight_smile:

1 Like

I think this is what you’re talking about

Game.rbxl (1.4 MB)

3 Likes
  1. Knife
swingrate = 0.9

anims={“GenericStab1”,“GenericStab2”,“StabPunch”,“Backstab”}
lastAnim = “”
bloodeffects = true

ready = false
equipped = false
lastswing = 0

local storage = script.Parent:WaitForChild(“Storage”)
local down = storage:WaitForChild(“MouseDown”)
local debris = game:GetService(“Debris”)
local state = script.Parent:WaitForChild(“SetState”)
local throw = script.Parent:WaitForChild(“RequestThrow”)
local animEvent = script.Parent:WaitForChild(“PlayAnimation”)
local soundEvent = script.Parent:WaitForChild(“PlayClientSound”)

function WaitFor(start,…)
local obj = start
for _,v in pairs{…} do
obj = obj:WaitForChild(v)
end
return obj
end

local player

while not player do
if script.Parent.Parent:IsA(“Model”) then
player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
elseif script.Parent.Parent:IsA(“Backpack”) then
player = script.Parent.Parent.Parent
end
end

function runsound(id,volume)
local volume = volume or 1
local sound = Instance.new(“Sound”)
sound.Looped = false
sound.Pitch = 1
sound.SoundId = “http://www.roblox.com/asset/?id=”…tostring(id)
sound.PlayOnRemove = false
sound.Volume = volume
debris:AddItem(sound,3)
sound.Parent = script.Parent.Handle
wait()
sound:Play()
end

function runAnimation(anim)
if anim == “Backstab” then
Spawn(function ()
script.Parent.GripUp = Vector3.new(0,-1,0)
wait(.55)
script.Parent.GripUp = Vector3.new(0,1,0)
end)
end
animEvent:FireAllClients(anim)
end

function clientSound(ref)
soundEvent:FireAllClients(ref)
end

b = Instance.new(“Part”)
b.BrickColor = BrickColor.new(“Bright red”)
b.formFactor = “Custom”
b.CanCollide = false
b.TopSurface = “Smooth”
b.BottomSurface = “Smooth”

function makeblood(part)
local bin = script.Parent.Parent:findFirstChild(“BloodBin”) or Instance.new(“Model”,script.Parent.Parent)
bin.Name = “BloodBin”
local function r(a,b)
– This is basically math.random with floats instead of integers.
a = a or 0; b = b or 1
return a+(b-a)<em>math.random()
end
if part then
local bl = b:clone()
bl.Transparency = r()</em>.5
bl.Size = Vector3.new(.2*r(1,5),.2,.2*r(1,5))
bl.Velocity = part.Velocity+(Vector3.new((r()-.5),(r()-.5),(r()-.5))<em>30)
bl.RotVelocity = part.RotVelocity+(Vector3.new((r()-.5),(r()-.5),(r()-.5))<em>20)
bl.CFrame = part.CFrame</em>CFrame.new((r()-.5)*3,(r()-.5)*3,(r()-.5)*3)*CFrame.Angles(math.pi*2*r(),math.pi*2*r(),math.pi</em>2*r())
bl.Parent = workspace
end
end

didHit = false
swinging = false

function ThrowAttack(_,target)
script.Parent.Enabled = false
script.Parent.Handle.Throw:Play()
wait(0.2)
local Handle = script.Parent.Handle
local Humanoid = script.Parent.Parent:findFirstChild(“Humanoid”)
local touchedConn
local throwingHandle
if Humanoid then
Handle.Archivable = true
throwingHandle = Handle:Clone()
throwingHandle.Name = “ThrownKnife”
throwingHandle.Transparency = 0
script.ThrowSmoke:clone().Parent = throwingHandle
game:GetService(“Debris”):AddItem(throwingHandle, 5)
throwingHandle.Parent = Humanoid.Parent
throwingHandle.Velocity = (target - throwingHandle.CFrame.p).unit * 200
throwingHandle.CFrame = CFrame.new(throwingHandle.CFrame.p, throwingHandle.CFrame.p + throwingHandle.Velocity) * CFrame.Angles(0, 0, math.rad(-90))
local floatingForce = Instance.new(‘BodyForce’, throwingHandle)
floatingForce.force = Vector3.new(0, 196.2 * throwingHandle:GetMass(), 0)
local spin = Instance.new(‘BodyAngularVelocity’, throwingHandle)
spin.angularvelocity = throwingHandle.CFrame:vectorToWorldSpace(Vector3.new(0, -400, 0))
end
wait(0.08)
if throwingHandle then
throwingHandle.CanCollide = true
Handle.Transparency = 1
touchedConn = throwingHandle.Touched:connect(function (hit)
if hit.Transparency == 1 then return end
if hit.Name == “Handle” then return end
if hit.Parent == Humanoid.Parent then return end
if hit.Parent:findFirstChild(“Humanoid”) == nil then return end
if throwingHandle.Transparency ~= 0 then return end
hit.Parent.Humanoid:TakeDamage(damage)
delay(3,function ()
(throwing) = false
script.Parent.Enabled = true
Handle.Transparency = 0
end)
clientSound(“Critical”)
throwingHandle.Anchored = true
for i = 1,10 do
throwingHandle.Transparency = i*.1
wait()
end
throwingHandle:Destroy()
touchedConn:disconnect()
end)
end
local proceed = true
for i = 1,80 do
if script.Parent.Enabled then
proceed = false
elseif proceed then
wait()
end
end
Handle.Transparency = 0
script.Parent.Enabled = true
throwing = false
end

function closestPlayerInSight(characters)
local torso = script.Parent.Parent:findFirstChild(“Torso”)
if torso then
local closestTorso,closestDist = nil,math.huge
for _,v in pairs(characters) do
local dist = (v.Torso.Position-torso.Position).magnitude
if dist <= 8 and dist < closestDist then
closestTorso = v.Torso
closestDist = dist
end
end
if closestTorso and closestDist then
return closestTorso.Parent
end
end
end

function Activate()
if equipped and (tick()-lastswing)>=swingrate and ready and script.Parent.Enabled and script.Parent.Handle.Transparency == 0 and script.Parent.Parent:findFirstChild(“Head”) then
script.Parent.Enabled = false
didHit = false
newanim = anims[math.random(1,#anims)]
runAnimation(newanim)
lastAnim = newanim
lastswing = tick()
swinging = true
local characters = {}
for _,v in pairs(game.Players:GetPlayers()) do
if v ~= player then
if v.Character and v.Character:findFirstChild(“Torso”) and v.Character:findFirstChild(“Humanoid”) and v.Character.Humanoid.Health > 0 then
table.insert(characters,v.Character)
end
end
end
for _,v in pairs(workspace:GetChildren()) do
if v:IsA(“Model”) and v:findFirstChild(“Humanoid”) and v.Humanoid.Health > 0 and v ~= script.Parent.Parent then
table.insert(characters,v)
end
end
for i = 1,6 do
if not didHit then
local userToKill = closestPlayerInSight(characters)
if userToKill then
userToKill.Humanoid:TakeDamage(damage)
didHit = true
clientSound(lastAnim == “Backstab” and “Critical” or “Normal”)
local numbloodeffects = lastAnim == “Backstab” and math.random(100,150) or math.random(20,40)
for i = 1,math.random(numbloodeffects-1,numbloodeffects+1) do
makeblood(userToKill.Torso)
end
end
end
wait(0.05)
end
if not didHit then – If we didn’t hit a player immediately, then play a swing sound to the server
script.Parent.Handle.Swing:Play()
end
swinging = false
didHit = false
wait(0.6)
script.Parent.Enabled = true
if down.Value then
Activate()
end
end
end

down.Changed:connect(function()
if down.Value then
Activate()
end
end)

hu = nil

script.Parent.Equipped:connect(function ()
ready = true
equipped = true
script.Parent.Handle.Transparency = 0
hu = script.Parent.Parent:findFirstChild(“Humanoid”)
if hu then
hu.WalkSpeed = 20
end
if down.Value then
Activate()
end
end)

state.OnServerEvent:connect(function (player,b)
down.Value = b
end)

throw.OnServerEvent:connect(ThrowAttack)

script.Parent.Unequipped:connect(function ()
down.Value = false
if hu then
hu.WalkSpeed = 20
hu = nil
end
ready = false
equipped = false
end)```

Knife Script
local parent = script.Parent
local Handle = parent:WaitForChild(“Handle”)
local Creator = parent:WaitForChild(“Creator”)
CanDmg = false
Can = true
parent.Equipped:Connect(function()
Handle.Equip:Play()
if Creator.Value == nil then
Creator.Value = parent.Parent end
end)
parent.Unequipped:Connect(function()
Handle.UnEquip:Play()
end)
repeat wait() until Creator.Value ~= nil
parent.Activated:Connect(function()
if Handle.Transparency == 1 then return end
function slash()
print(“hip”)
local creator = Creator.Value
local Animations = parent:WaitForChild(“Animations”)
local AnimChild = Animations:GetChildren()
local AnimRad = math.random(1,#AnimChild)
local AnimSel = AnimChild[AnimRad]
local AP = creator:WaitForChild(“Humanoid”):LoadAnimation(AnimSel)
if Can == true then
Can = false
AP:Play()
wait(0.15)
CanDmg = true
Handle.Swing:Play()
Handle.SlashTrail.Enabled = true
wait(0.25)
CanDmg = false
Handle.SlashTrail.Enabled = false
wait(0.06)
Can = true
end
end
slash()
end)
function on(t)
local h = t.Parent:FindFirstChildOfClass(“Humanoid”)
if h ~= nil and CanDmg == true then
CanDmg = false
local cre = Creator.Value
h:TakeDamage(parent.Dmg.Value)
Handle.Swing:Stop()
Handle.Hit:Play()
if h.Health>0 then
if not h:FindFirstChild(“creator”) then
local ov = Instance.new(“ObjectValue”,h)
ov.Name = “creator”
ov.Value = game.Players:WaitForChild(cre.Name)
else
local ovs = h:GetChildren()
for i = 1,#ovs do
if (ovs[i].Name == “creator”) then
ovs[i].Value = game.Players:WaitForChild(cre.Name) end
end
end
end
end
end
Handle.Touched:Connect(on)

Local Knife
local storage = script.Parent:WaitForChild(“Storage”)
local down = storage:WaitForChild(“MouseDown”)
local runanim = storage:WaitForChild(“RunAnim”)
local cs = script.Parent:WaitForChild(“PlayClientSound”)
local state = script.Parent:WaitForChild(“SetState”)
local throw = script.Parent:WaitForChild(“RequestThrow”)
local animEvent = script.Parent:WaitForChild(“PlayAnimation”)

animspeed = 1
equipspeed = 1.5
throwing = false

function WaitForChildren(start,…)
if not start:IsA(“Instance”) then return end
local currentObj = start
for _,v in pairs{…} do
if type(v) == “string” then
currentObj = currentObj:WaitForChild(v)
end
end
return currentObj
end

function update(mouse)
if mouse ~= nil then
mouse.Icon = script.Parent.Enabled and “rbxasset://textures\GunCursor.png” or “rbxasset://textures\GunWaitCursor.png”
end
end

heatStorage = {}

local hitSound
local input = game:GetService(“UserInputService”)
local isMobile = input.TouchEnabled

function ClientThrow(target)
– I’m doing this to remove the lag factor of the knife from the client’s perspective
– This knife doesn’t actually do anything to the players, its basically simulating what the server is doing
– Worse case scenario: Accuracy and latency screw it up
local Handle = script.Parent.Handle
local serverKnife = script.Parent.Parent:WaitForChild(“ThrownKnife”)
local clientKnife = Handle:Clone()
clientKnife.Transparency = 0
clientKnife.CanCollide = false
game:GetService(“Debris”):AddItem(clientKnife, 5)
clientKnife.Parent = workspace.CurrentCamera
clientKnife.Velocity = (target - clientKnife.CFrame.p).unit * 200
clientKnife.CFrame = serverKnife.CFrame
local floatingForce = Instance.new(‘BodyForce’, clientKnife)
floatingForce.force = Vector3.new(0, 196.2 * clientKnife:GetMass(), 0)
local spin = Instance.new(‘BodyAngularVelocity’, clientKnife)
spin.angularvelocity = clientKnife.CFrame:vectorToWorldSpace(Vector3.new(0, -400, 0))
serverKnife.Changed:connect(function (property)
if property == “Anchored” then
clientKnife.Anchored = true
clientKnife.CFrame = serverKnife.CFrame
for i = 1,10 do
clientKnife.Transparency = i*.1
wait()
end
clientKnife:Destroy()
end
end)
end

function runAnimation(an)
local h = game.Players.LocalPlayer.Character:findFirstChild(“Humanoid”)
local anim = storage:findFirstChild(an)
if anim and h then
local theanim = h:LoadAnimation(anim)
if theanim and h.Health > -100 then
theanim:Play(nil,nil,animspeed)
if anim.Name == “Backstab” then
script.Parent.GripUp = Vector3.new(0,-1,0)
wait(.75)
script.Parent.GripUp = Vector3.new(0,1,0)
end
delay(1,function ()
theanim:Stop()
end)
end
end
end

animEvent.OnClientEvent:connect(runAnimation)

throwing = false

function setKnifeState(b)
b = throwing and false or b
state:FireServer(b)
end

function requestThrow()
if script.Parent.Handle.Transparency == 0 and not throwing and script.Parent.Enabled then
throwing = true
runAnimation(“Throw”)
local hit = game.Players.LocalPlayer.Character.Humanoid.TargetPoint
throw:FireServer(hit)
ClientThrow(hit)
wait(3)
throwing = false
end
end

function Equipped(mouse)
hitSound = game.Players.LocalPlayer.PlayerGui:findFirstChild(“Sound”) or Instance.new(“Sound”)
hitSound.SoundId = “http://www.roblox.com/asset/?ID=186311262”
hitSound.Parent = game.Players.LocalPlayer.PlayerGui
for _,v in pairs(game.Players:GetPlayers()) do
if v.Character and v.Character.Humanoid.Health > 0 and v.Character:findFirstChild(“Torso”) and v.Character ~= game.Players.LocalPlayer.Character then
local heat = storage.Heat:clone()
heat.Parent = game.Players.LocalPlayer.PlayerGui
heat.Adornee = v.Character.Torso
heat.Enabled = true
table.insert(heatStorage,heat)
v.Character.Humanoid.Died:connect(function ()
heat:Destroy()
end)
heat.Adornee.Changed:connect(function ()
if not heat.Adornee or heat.Adornee.Parent == nil then
heat:Destroy()
end
end)
heat.Changed:connect(function ()
if not heat.Adornee then
heat:Destroy()
end
local scale = math.sqrt(heat.AbsoluteSize.X^2+heat.AbsoluteSize.Y^2)
heat.ImageLabel.Visible = scale > 30
end)
end
end
local input = game:GetService(“UserInputService”)
mouse.Button1Down:connect(function ()
setKnifeState(true)
end)
mouse.Button1Up:connect(function ()
setKnifeState(false)
end)
mouse.Button2Down:connect(function ()
requestThrow()
end)
input.TouchTap:connect(function ()
setKnifeState(true)
wait(.2)
setKnifeState(false)
end)
input.TouchLongPress:connect(function ()
requestThrow()
end)
mouse.Icon = script.Parent.Enabled and “rbxasset://textures/GunCursor.png” or “rbxasset://textures/GunWaitCursor.png”
script.Parent.Changed:connect(function ()
mouse.Icon = script.Parent.Enabled and “rbxasset://textures/GunCursor.png” or “rbxasset://textures/GunWaitCursor.png”
end)
end

function Unequipped()
for _,v in pairs(heatStorage) do
v:Destroy()
end
heatStorage = {}
if hitSound then
hitSound:Destroy()
end
end

script.Parent.Equipped:connect(Equipped)
script.Parent.Unequipped:connect(Unequipped)

cs.OnClientEvent:connect(function (value)
if hitSound then
hitSound.SoundId = (value == “Normal”) and “http://www.roblox.com/asset/?ID=186311262” or “http://www.roblox.com/asset/?ID=186311262”
hitSound.Pitch = 1,0 +(math.random()/1)
hitSound:Play()
end
end)

I think this is what you are thinking and I tried to correct it and I hope you will find it easy to read.
3 Likes

Hello, I’ve figured out the issue with your knife weapon.
In each of your knife weapons there is an IntValue called “Dmg”

this IntValue dictates the damage that it does to the player. Change the value of this to 100
to do 100 damage

This is for ALL the knifes you have in the starterpack.

3 Likes

Thanks a lot for your solution, it really worked. I will tell you 2 things, one of them is that after changing this setting, when I kill in the Kills section, the +1 number does not come. 2. Can I get your support on another issue? again in the same game.

2 Likes

Happy to help!

  1. . I assume that you’re talking about the kills in leaderstats. To increment the value of “kills” I can’t necessarily code everything for you but I will tell you how I would do it. I would fire a remote event from a script to a local script where I would look for the leaderstats folder in the player and get the value of “Oldurmeler” and add 1 to it when the humanoid’s health <= 0.

  2. . I think it would be best for you to start a new topic to solve your issue so that others who need support on the new issue you’re having can easily find a fix in a new topic you’re making. Plus, by adding a new topic, people who may have a more stronger knowledge in your issue can easily find that topic and quickly answer it.

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