Player cannot use knife, he will lose the game!

Hello, I was going about my business scripting a knife but it seems to not work. The problem is the animation will not play.

Here is my script (it is the local script called “Client”)

--Main
local knife = script.Parent.Parent
local handle = knife:WaitForChild("Handle")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

--folders
local animationsFolder = knife:WaitForChild("Animations")
local eventsFolder = knife:WaitForChild("Events")
local functionsFolder = knife:WaitForChild("Functions")
local scriptsFolder = knife:WaitForChild("Scripts")
local soundsFolder = knife:WaitForChild("Sounds")

--scripts 
local serverScript = scriptsFolder:WaitForChild("Server")
local clientScript = scriptsFolder:WaitForChild("Client")
local moduleScript = scriptsFolder:WaitForChild("Module")

--animation
local swingAnimation = animationsFolder:WaitForChild("Slash")
local animationTrack = humanoid:LoadAnimation(swingAnimation)

--sounds
local hit = soundsFolder:WaitForChild("Hit")
local swoosh = soundsFolder:WaitForChild("Swoosh")
local stab = soundsFolder:WaitForChild("Stab")
local equip = soundsFolder:WaitForChild("Equip")
local unequip = soundsFolder:WaitForChild("Unequip")

--handle children (important)
local decal = handle:WaitForChild("Skin")

--local functions
local function onEquip()
	--play equip sound
end

local function onUnequip()
	--play unequip sound
end

local function onActivation()
	--play swoosh sound
	if swoosh then
		swoosh:Play()
	end
	--play swing animation
	animationTrack:Play()
		--if hit, play hit sound
	--if hit = player, play stab sound
	--give damage
end

--events
knife.Equipped:Connect(onEquip)
knife.Unequipped:Connect(onUnequip)
knife.Activated:Connect(onActivation)

Here is my explorer.
image

2 Likes

Is the animation owned by you? Any errors?

1 Like

No errors and It is owned by me.

1 Like

does anything in your console say infinite yield?

1 Like

No, there is nothing in the output.

1 Like

Maybe put a print() in your activation function to see if it runs

3 Likes

I printed a message before and after the animation should have played. It seems it should work. It prints both messages.

I already tried using the animator, it still did not work.

Still no progress…It doesn’t make any sense.

Is the animation priority set to “Action”?

It may seem a small oversight at first, but due to how roblox handles animation playing it is actually a huge deal.
While it CAN be changed via script, i highly advise against doing so as it can lead to replication problems.

I suggest going into the animation editor and loading all the animations just to check, and in case of any not being set to action, set them to that.

1 Like