Several issues with my shove script


local shoveCooldown = 5 --in seconds, how long the cooldown for the shove is
local shovePower = 1000 --how much power the shove has
local shoveDuration = 3 --how long, in seconds, the shove disables the jumping of the shoved player


function shoved(hit, plr)

	print(plr.Name)

	--check if "hit" was a member of a humanoid

	if hit.Parent:FindFirstChild("Humanoid") then

		--check if hit is a player
		if game.Players:GetPlayerFromCharacter(hit.Parent) then

			local shovedPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)


			--if the shoved player is not already ragdolled,
			if shovedPlayer.Character:FindFirstChild("Humanoid"):GetState() ~= Enum.HumanoidStateType.Ragdoll then
				
				
				print("shoved " ..shovedPlayer.Name)
				
				
				--ragdoll them, disable their jump power
				local jumpHeight = shovedPlayer.Character:FindFirstChild("Humanoid").JumpHeight --get original jumpheight to return to
				
				shovedPlayer.Character:FindFirstChild("Humanoid").JumpHeight = 0
				shovedPlayer.Character:FindFirstChild("Humanoid"):ChangeState(Enum.HumanoidStateType.Ragdoll)
				
				--apply impulse based on look vector and shovePower
				shovedPlayer.Character:FindFirstChild("Torso"):ApplyImpulse(-(plr.Character.Torso.CFrame.LookVector.Unit * shovePower))
				
				--task.spawn to reset the players jump height
				task.spawn(function()
					wait(shoveDuration)
					if shovedPlayer.Character then
						shovedPlayer.Character:FindFirstChild("Humanoid").JumpHeight = jumpHeight
					end
				end)
				
			end


		end

	end

end

There’s quite a variety of bugs with this and I don’t quite understand why it won’t work.

  1. The player is never actually shoved. As far as I can see, there’s no ragdolling, no knockback whatsoever- it looks like the player just stands there, honestly.
  2. The shoved player does seem to have their jumpheight set to 0- but it never again goes back up to the normal value I set.

The print statements are working- both print statements go off exactly as expected during the testing.

Why is this going wrong?

I’m pretty sure the Ragdoll humanoid state type isn’t what you want. Why don’t you just add a bool value or attribute to the humanoid that changes when the character is ragdolled?

If you want to see more about what the state types are and what they mean:

then which one do i want?

character limittt

Not sure. I suggest you just don’t use state types and just use a bool value inside the character instead.