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.
- 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.
- 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?