Changing a player's PhysicalState (Falling Down) from a tool

Hello.
I have been creating a push tool. It changes the Physical State of the person hit by it into a falling down state, when it touches the handle.
Here’s the problem: whenever I push a player, it does not work. However, pushing NPC’s works perfectly.
This is strange behavior, can somebody please help me?

local debounce = false

script.Parent.Handle.Touched:Connect(function(hit)
	if debounce then return end
	debounce = true

	print("Part was touched")
	if hit.Parent:FindFirstChild("Humanoid") then
		
		hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 10 
		hit.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.FallingDown)
	end

	wait(0.25)

end)

I feel like the state of the humanoid the local player is controlling needs to be changed locally. (since physics are done local-sided for their character)

Could be totally wrong on this though, but you could give it a shot just to see.

1 Like

How do you suggest I go around this, considering that this script is inside of the tool?

You could fire a RemoteEvent stored in like ReplicatedStorage, using its :FireClient() method to the player that was touched, and then do something like this in a LocalScript:

pathToRemote.OnClientEvent:Connect(function()
playerHumanoid:ChangeState(Enum.HumanoidStateType.FallingDown)
end)
1 Like

I have this in StarterPlayerScripts, in a LocalScript.

game:GetService("ReplicatedStorage").RemoteEvent.OnClientEvent:Connect(function()
	script.parent.Humanoid:ChangeState(Enum.HumanoidStateType.FallingDown
	print("received")
end)

I have my RemoteEvent in Replicated Storage.
This is my Modified Code (Inside of my push tool)

script.Parent.Handle.Touched:Connect(function(hit)
	if debounce then return end
	debounce = true

	print("Part was touched")

	if hit.Parent:FindFirstChild("Humanoid") then
		
		hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -10
		hit.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.FallingDown)
		script.parent.Punch.Playing=true
		local ReplicatedStorage = game:GetService("ReplicatedStorage")

		local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

		remoteEvent:FireClient(hit.Parent)
	end

	wait(0.25)
	debounce = false

end)

It does not work. Do you know what I did wrong?
I believe I’m doing this completely wrong.

Try this instead:

game:GetService("ReplicatedStorage").RemoteEvent.OnClientEvent:Connect(function()
    local character = game.Players.LocalPlayer.Character

	character.Humanoid:ChangeState(Enum.HumanoidStateType.FallingDown)
	print("received")
end)

And also :FireClient() takes the player as an argument, not the character. So try this:

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

if player then
    remoteEvent:FireClient(player)
end

Thank you. That makes so much more sense.

1 Like