Hello there,
I have a knife tool that has been working, but recently stopped working and im unsure why. It appears to be working on older maps, yet there is no changes made when bringing the tool over to the next place.
The knife is set to a Collison group, and I’ve double checked to make sure everything is set up correctly.
Server
local assets = script.Parent.Assets
local events = assets.Events
events.Damage.OnServerEvent:Connect(function(plr,b,d,db,trg)
local function bleed()
script.Parent.Assets.Sounds["hit"..math.random(1,2)]:Play()
local Particles = Instance.new("ParticleEmitter")
Particles.Enabled = false
Particles.Color = ColorSequence.new(Color3.fromRGB(125, 0, 0))
Particles.LightEmission = 0
Particles.LightInfluence = 1
Particles.Size = NumberSequence.new(.15,1.5)
Particles.Texture = "rbxasset://textures/particles/smoke_main.dds"
Particles.Transparency = NumberSequence.new(
{
NumberSequenceKeypoint.new(0, 0.5, 0);
NumberSequenceKeypoint.new(1, 1);
}
)
Particles.Acceleration = Vector3.new(0, 5, 0)
Particles.Lifetime = NumberRange.new(.25, 1)
Particles.Rate = 2000
Particles.Drag = 10
Particles.RotSpeed = NumberRange.new(-150,150)
Particles.Speed = NumberRange.new(7 ,15)
Particles.VelocitySpread = math.random(2,20)
Particles.SpreadAngle = Vector2.new(-150,150)
Particles.LockedToPart = true
Particles.Parent = trg
Particles.EmissionDirection = "Front"
Particles:Emit(50)
game.Debris:AddItem(Particles,Particles.Lifetime.Max)
end
if b then
trg.Parent:FindFirstChild("Humanoid"):TakeDamage(db)
bleed()
if trg.Parent:FindFirstChild("Humanoid").Health < 5 then
plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + game.ReplicatedStorage.Values.Points.Value
else
plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + game.ReplicatedStorage.Values.ShootPoints.Value
end
else
trg.Parent:FindFirstChild("Humanoid"):TakeDamage(d)
bleed()
if trg.Parent:FindFirstChild("Humanoid").Health < 5 then
plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + game.ReplicatedStorage.Values.Points.Value
else
plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + game.ReplicatedStorage.Values.ShootPoints.Value
end
end
end)
Client
repeat wait() until game.Loaded
local ContentProvider = game:GetService("ContentProvider")
local char = game.Players.LocalPlayer.Character
local cam = workspace.Camera
local run = game:GetService("RunService")
local equipped = false
local assets = script.Parent:WaitForChild("Assets")
ContentProvider:PreloadAsync({assets.Animations.Idle})
ContentProvider:PreloadAsync({assets.Animations.Melee})
local item = assets.VM:WaitForChild("Viewmodel")
local bob = require(assets.Modules.Bobble)
local useDebounce = true
local useCooldown = 1
local gun = item
local VMLeftArm = gun:FindFirstChild("Left Arm")
local VMRightArm = gun:FindFirstChild("Right Arm")
local Animations = assets.Animations
local Config = require(assets.Config)
local Track1
local Track2
local bowie = Config.bowie
run.RenderStepped:Connect(function(dt)
if equipped then
gun.PrimaryPart.CFrame = cam.CFrame*CFrame.new(0,-.15,0)
bob.Bob(dt,gun,"Idle")
else
coroutine.yield()
end
end)
run.RenderStepped:Connect(function()
if equipped then
local camCF = game.Workspace.CurrentCamera.CoordinateFrame
local distance = (script.Parent.Parent.Head.Position - camCF.p).magnitude
if distance <= 1.7 and script.Parent.Parent.Humanoid.Health ~= 0 and equipped then
if char:FindFirstChildOfClass("Shirt") then
local shirt = char:FindFirstChildOfClass("Shirt")
if not gun:FindFirstChild("Shirt") then
shirt:Clone().Parent = gun
gun["Left Arm"].BrickColor = char:WaitForChild("Left Arm").BrickColor
gun["Right Arm"].BrickColor = char:WaitForChild("Right Arm").BrickColor
else
--gun:FindFirstChild("Shirt"):Destroy()
shirt:Clone().Parent = gun
gun["Left Arm"].BrickColor = char:WaitForChild("Left Arm").BrickColor
gun["Right Arm"].BrickColor = char:WaitForChild("Right Arm").BrickColor
end
end
gun.Parent = cam
if bowie then
gun.Knife.one.Transparency = 1
gun.Knife.two.Transparency = 0
else
gun.Knife.one.Transparency = 0
gun.Knife.two.Transparency = 1
end
else
gun.Parent = game.ReplicatedFirst
end
end
end)
function melee()
Track1:Stop()
Track2:Play()
delay(.25,function()
script.Parent.Assets.Sounds["whoosh"..math.random(1,3)]:Play()
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {cam,char}
raycastParams.IgnoreWater = true
local raycastResult = workspace:Raycast(cam.CFrame.p + Vector3.new(0,-0.5,0), cam.CFrame.LookVector*8, raycastParams)
if raycastResult then
if raycastResult.Instance.Parent.Parent == workspace.Zombies then
assets.Events.Damage:FireServer(Config.bowie,Config.damage,Config.bowiedamage,raycastResult.Instance)
end
end
delay(.6,function()
if not gun:FindFirstChild("Shirt") then
gun:FindFirstChild("Shirt"):Destroy()
else
gun:FindFirstChild("Shirt"):Destroy()
end
char.Humanoid:UnequipTools()
end)
end)
end
script.Parent.Equipped:Connect(function()
equipped = true
Track1 = gun.Humanoid:LoadAnimation(Animations.Idle)
Track2 = gun.Humanoid:LoadAnimation(Animations.Melee)
Track1.Priority = Enum.AnimationPriority.Idle
Track2.Priority = Enum.AnimationPriority.Action4
Track1:Play()
melee()
end)
script.Parent.Unequipped:Connect(function()
gun.Parent = assets.VM
equipped = false
end)
The knife is equipped via another script inside the character model.
There is some modules as well, but i dont think they’re the cause.
Same tool in another place that has been working
Same tool in a new place im working on
fyi this is all in the same universe.