:ChangeState() method not working on server

My goal is to make the auto jump system to make the player jump 10 times every 10 second if the signal type is “autojump” and I also want the freeze system to freeze player when signal type is “freeze” by set speed to 0 and disable jumping state of humanoid. But, the main problem is the :ChangeState() not working and I assuming it is something relate about between the client and server.

Server:

EventsManager.OnServerEvent:Connect(function(Player: Player, SignalType: string, ClientData: {})
	SignalType = string.lower(tostring(SignalType))
	
	if SignalType == 'fling' then
		EventsManager:FireAllClients('sendchatmsg', {
			MessageData = {
				Text = `{ClientData.Target.DisplayName} has been trolled by {Player.DisplayName} using fling troll`,
				Color = Color3.fromRGB(255, 0, 0),
			};
			
			Message = `<font color = "rgb(255, 0, 0)">{ClientData.Target.DisplayName} has been trolled by {Player.DisplayName} using fling troll</font>`
		})
		
		local TargetChar = ClientData.Target.Character or ClientData.Target.CharacterAdded:Wait()
		local TargetHrp = TargetChar:WaitForChild('HumanoidRootPart') or TargetChar.PrimaryPart
		local TargetHum = TargetChar:WaitForChild('Humanoid')
		
		local NewRagdoll = RagdollModule.new(TargetChar, {
			KnockbackOnRagdoll = {
				Enabled = true;
				Direction = TargetChar:GetPivot().Position + TargetChar:GetPivot().UpVector * 120;
				Duration = .35;
			};

			DamageOnRagdoll = {
				Enabled = false;
				Damage = 10;
			};
		})
		
		TargetHrp.CanCollide = false
		NewRagdoll:Run('Ragdoll')
		
		task.delay(5, function()
			NewRagdoll:Run('Recover')
			TargetHrp.CanCollide = true
		end)
	elseif SignalType == 'explode' then
		EventsManager:FireAllClients('sendchatmsg', {
			MessageData = {
				Text = `{ClientData.Target.DisplayName} has been trolled by {Player.DisplayName} using explode troll`,
				Color = Color3.fromRGB(255, 0, 0),
			};

			Message = `<font color = "rgb(255, 0, 0)">{ClientData.Target.DisplayName} has been trolled by {Player.DisplayName} using explode troll</font>`
		})
		
		local TargetChar = ClientData.Target.Character or ClientData.Target.CharacterAdded:Wait()
		local TargetHrp = TargetChar:WaitForChild('HumanoidRootPart') or TargetChar.PrimaryPart
		
		local Explosion = Instance.new('Explosion', TargetHrp)
		Explosion.Position = TargetHrp.Position
		Explosion.BlastPressure = 10000
	elseif SignalType == 'kick' then
		ClientData.Target:Kick(`You have been trolled by {Player.Name}`)
	elseif SignalType == 'kill' then
		local TargetChar = ClientData.Target.Character or ClientData.Target.CharacterAdded:Wait()
		local TargetHum = TargetChar:WaitForChild('Humanoid')
		
		TargetHum:TakeDamage(TargetHum.MaxHealth)
	elseif SignalType == 'autojump' then
		local TargetHum = ClientData.Hum

		if not JumpsList[TargetHum] then
			JumpsList[TargetHum] = 0
		end
		
		task.spawn(function()
			while JumpsList[TargetHum] and JumpsList[TargetHum] < 10 do
				task.wait(1)

				JumpsList[TargetHum] += 1

				TargetHum:ChangeState(Enum.HumanoidStateType.Dead)
				print(TargetHum:GetState())
				
				if JumpsList[TargetHum] >= 10 then
					print(TargetHum)
					JumpsList[TargetHum] = 0
				end
			end
		end)
	elseif SignalType == 'freeze' then
		
		local TargetHum = ClientData.Hum
		
		print(TargetHum)
		
		TargetHum.WalkSpeed = 0
		TargetHum:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
		
		task.delay(10, function()
			TargetHum.WalkSpeed = StarterPlayer.CharacterWalkSpeed
			TargetHum:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
		end)
	end
end)

Client:

AutojumpBtn.MouseButton1Click:Connect(function()
	local SpectateValue = Char:FindFirstChild('SpectateTarget')

	if SpectateValue and SpectateValue:IsA('ObjectValue') then
		assert(SpectateValue.Value and SpectateValue.Value:IsA('Player'), 'SpectateValue value is not a player!!')
		
		local TargetChar = SpectateValue.Value.Character or SpectateValue.Value.CharacterAdded:Wait()
		local TargetHum = TargetChar:WaitForChild('Humanoid')

		EventsManager:FireServer('AutoJump', {
			Hum = TargetHum
		})
	end
end)

FreezeBtn.MouseButton1Click:Connect(function()
	local SpectateValue = Char:FindFirstChild('SpectateTarget')

	if SpectateValue and SpectateValue:IsA('ObjectValue') then
		assert(SpectateValue.Value:IsA('Player'), 'SpectateValue value is not a player!!')
		
		local TargetChar = SpectateValue.Value.Character or SpectateValue.Value.CharacterAdded:Wait()
		local TargetHum = TargetChar:WaitForChild('Humanoid')
		
		EventsManager:FireServer('Freeze', {
			Hum = TargetHum
		})
	end
end)

Any solutions will be appreciated!! Thank you for your help.

Modify the freeze section

elseif SignalType == 'freeze' then
	local TargetHum = ClientData.Hum

	print(TargetHum)
	
	TargetHum.WalkSpeed = 0
	TargetHum.JumpPower = 0  -- Disable jumping by setting JumpPower to 0
	TargetHum:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
	
	task.delay(10, function()
		TargetHum.WalkSpeed = StarterPlayer.CharacterWalkSpeed
		TargetHum.JumpPower = StarterPlayer.CharacterJumpPower  -- Re-enable jumping by restoring JumpPower
		TargetHum:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
	end)
end

Now modify it the auto jump section like this too

elseif SignalType == 'autojump' then
	local TargetHum = ClientData.Hum

	if not JumpsList[TargetHum] then
		JumpsList[TargetHum] = 0
	end
	
	task.spawn(function()
		while JumpsList[TargetHum] and JumpsList[TargetHum] < 10 do
			task.wait(1)

			JumpsList[TargetHum] += 1

			TargetHum:ChangeState(Enum.HumanoidStateType.Jumping)  -- Set the state to Jumping
			print(TargetHum:GetState())
			
			if JumpsList[TargetHum] >= 10 then
				print(TargetHum)
				JumpsList[TargetHum] = 0
			end
		end
	end)
1 Like

the script still doesn’t make it work.

So what solutions have you tried so far and I need the output window for maybe some context to see and fix or diagnose it

I have debugged the humanoid. The humanoid successfully recieved on server, I also tried to do it on client but it doesn’t work too. The problem rn is the humanoid is not changing state correctly and the others stuff run just fine. I used an ObjectValue to store the player there then get the humanoid and send it to server to change the state but state is not changing.

Which :ChangeState() is not working?

The Auto Jump one are not working.

Also. The ObjectValue is being set on client just a reminder.

Update: The freeze is now working on server.

Nvm guys. I made the system work.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.