You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to make a simple knife weapon. -
What is the issue? Include screenshots / videos if possible!
The touch events won’t work. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried messing with the touched events but no luck.
Stuff:
--Client script
local tool = script.Parent.Parent
local remotesFolder = tool:WaitForChild("Remotes")
local sliceEvent = remotesFolder:WaitForChild("SliceEvent")
local animsFolder = tool:WaitForChild("Anims")
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local walkAnim = humanoid:LoadAnimation(animsFolder:WaitForChild("WalkAnim"))
local slice1Anim = humanoid:LoadAnimation(animsFolder:WaitForChild("Slice1Anim"))
local throttle = false
local function doSliceAttack()
if not throttle then
throttle = true
sliceEvent:FireServer()
slice1Anim:Play()
wait(1.5)
throttle = false
end
end
tool.Activated:Connect(doSliceAttack)
--Server script
local tool = script.Parent.Parent
local remotesFolder = tool:WaitForChild("Remotes")
local sliceEvent = remotesFolder:WaitForChild("SliceEvent")
local murderKnife = tool:WaitForChild("Handle")
local effectsFolder = tool:WaitForChild("Effects")
local knifeTrail = effectsFolder:WaitForChild("KnifeTrail")
local soundsFolder = tool:WaitForChild("Sounds")
local equipSound = soundsFolder:WaitForChild("EquipSound")
local sliceSound = soundsFolder:WaitForChild("SliceSound")
local throttle = false
local hasBeenTouched = {}
local function doSliceAttack()
if not throttle then
throttle = true
knifeTrail.Enabled = true
local steppedConnection = murderKnife.Touched:Connect(function(touched)
local touchedParent = touched.Parent
if not hasBeenTouched[touchedParent] then
hasBeenTouched[touchedParent] = true
local humanoid = touchedParent:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(100)
sliceSound:Play()
end
end
end)
wait(0.75)
knifeTrail.Enabled = false
wait(0.25)
steppedConnection:Disconnect()
hasBeenTouched = {}
wait(1.5)
throttle = false
end
end
sliceEvent.OnServerEvent:Connect(doSliceAttack)