Which is better? [Stun System]

Title says it all.

---Variables
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")

Fireclient:

game.ReplicatedStorage.Client.OnClientEvent:Connect(function(Arg)
if Arg == "Stunned" then
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 0

repeat wait()
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 0
until not Player.Status:FindFirstChild("Stunned")

Humanoid.WalkSpeed = 16
Humanoid.JumpPower = 50
end
end)

RenderStepped:

game:GetService("RunService").RenderStepped:Connect(function()
if Player.Status:FindFirstChild("Stunned")  then
Humanoid.WalkSpeed = 0
else
Humanoid.WalkSpeed = 16
end
end)

I know the renderstepped and fireclient will have some bugs(like overlapping walkspeed etc), but for the sake of comparison let’s pretend I fixed those. Which is better for the stun system? or are they both basically the same? I’m looping them just in case exploiters try to change their walkspeed, so that it can somewhat prevent it.

It should work, but what if you use Humanoid.PlatformStand?

Edit: I’d suggest the first one by the way.

1 Like

There’d be multiple effects for the stuff I’m doing such as slowness, can’t jump and react to hits(getting slowed when punched), etc so I just chose to alternate the walkspeed instead for easier modification I guess, and I never touched Platformstand cause I’ve never seen games with somewhat realistic combat use that and it clips through the platform.

1 Like

Yes, it does clip through the platforms at times. I haven’t had a need to make stun effects so I haven’t researched a solution.

You can make a stun folder in StarterCharacter and everytime you want someone to be stunned make a number value called “Stun” , make the value how long you want them to be stun, and then add the Stun value to the Stun Folder.

local Character = script.Parent
local Stuns = Character.StunFolder


local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
	Stuns.ChildAdded:Connect(function(Chi) -- Chi is the object
		Humanoid.WalkSpeed = 0
		Humanoid.JumpPower = 0
	
		wait(Chi.Value)
		Chi:Destroy()
		repeat game:GetService("RunService").Heartbeat:Wait() until not Stuns:FindFirstChild("Stun")
		Humanoid.WalkSpeed = 16
		Humanoid.JumpPower = 50
end)

The script above would be placed in a local script in starterCharacter

1 Like

Is using

game:GetService("RunService").Heartbeat:Wait()

better than wait()?

Yes, Heartbeat is faster than wait.
This post explains it pretty well, RenderStepped, Stepped, or Heartbeat

1 Like

Aight thank ya’ll for responding I guess I’m in the right track.

what if there was 2 stun values?