I want to create a stagger system for my combat and I currently am using remove events to handle when it should stagger and who, only problem was I had to get the hit player as the first argument in the removeEvent:FireClient() and I used GetPlayerFromCharacter to get the player from the hithumanoid, but its returning nil and I do not know why.
I use a hitbox system called ClientCast for hit detection by the way, here is the code:
slashCaster.HumanoidCollided:Connect(function(result, hithumanoid)
if script.Parent.Equipped then
if Debounce[hithumanoid] then
return
end
Debounce[hithumanoid] = true
print("Hit:" .. result.Instance.name)
game.ReplicatedStorage.Events.GoreEvent:FireAllClients(math.random(config.MinBlood.Value, config.MaxBlood.Value), result.Instance.Position)
hithumanoid:TakeDamage(config.Damage.Value)
script.Parent.Handle.Hit:Play()
local hal = Instance.new("Animation")
hal.AnimationId = "http://www.roblox.com/asset/?id=7747707560"
local har = Instance.new("Animation")
har.AnimationId = "http://www.roblox.com/asset/?id=7747710892"
local hurtAnimLeft = hithumanoid:LoadAnimation(hal)
local hurtAnimRight = hithumanoid:LoadAnimation(har)
local ranMath = math.random(1, 2)
if ranMath == 1 then
hurtAnimLeft:Play()
elseif ranMath == 2 then
hurtAnimRight:Play()
end
local player = players:GetPlayerFromCharacter(hithumanoid.Parent)
So what would I do if its not a player? Would I need an additional check before I fire the stagger event or something else? Because I have dummies that I would like to be staggered as well.
Well what does staggered mean? Like a client screen effect? If it’s a NPC than it wouldn’t have a client or screen to effect anyway so I am confused?
It slows the players walkspeed, then waits the staggertime then goes back to normal walkspeed. Here is the stagger code(its a localscript in startercharacterscripts, I know its not safe to handle this on the client but I’m not sure how else to handle something like this):
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.Events.Stagger.OnClientEvent:Connect(function(hum, staggertime, staggeramount)
local OldWalkSpeed = hum.WalkSpeed
hum.WalkSpeed = staggeramount
wait(staggertime)
hum.WalkSpeed = OldWalkSpeed
end)
I haven’t really thought this through honestly, I have no idea how coroutines work so I’ll look at the API and see if it works, thanks for the help.
slashCaster.HumanoidCollided:Connect(function(result, hithumanoid)
if script.Parent.Equipped then
if Debounce[hithumanoid] then
return
end
Debounce[hithumanoid] = true
print("Hit:" .. result.Instance.name)
game.ReplicatedStorage.Events.GoreEvent:FireAllClients(math.random(config.MinBlood.Value, config.MaxBlood.Value), result.Instance.Position)
hithumanoid:TakeDamage(config.Damage.Value)
script.Parent.Handle.Hit:Play()
local hal = Instance.new("Animation")
hal.AnimationId = "http://www.roblox.com/asset/?id=7747707560"
local har = Instance.new("Animation")
har.AnimationId = "http://www.roblox.com/asset/?id=7747710892"
local hurtAnimLeft = hithumanoid:LoadAnimation(hal)
local hurtAnimRight = hithumanoid:LoadAnimation(har)
local ranMath = math.random(1, 2)
if ranMath == 1 then
hurtAnimLeft:Play()
elseif ranMath == 2 then
hurtAnimRight:Play()
end
local OldWalkSpeed = hithumanoid.WalkSpeed
hithumanoid.WalkSpeed = staggeramount
wait(staggertime)
hithumanoid.WalkSpeed = OldWalkSpeed
This should work both on an NPC and a real Player. If it worked, it would be appreciated to be set as solution
Still doesn’t seem to work, I’m not sure why. I had to put the walkspeed changes closer to the end of the function so it wouldn’t make the hit debounce longer, since it gets changed at the end of the function.
Here is the entire function that handles hit detection:
slashCaster.HumanoidCollided:Connect(function(result, hithumanoid)
if script.Parent.Equipped then
if Debounce[hithumanoid] then
return
end
Debounce[hithumanoid] = true
print("Hit:" .. result.Instance.name)
game.ReplicatedStorage.Events.GoreEvent:FireAllClients(math.random(config.MinBlood.Value, config.MaxBlood.Value), result.Instance.Position)
hithumanoid:TakeDamage(config.Damage.Value)
script.Parent.Handle.Hit:Play()
local hal = Instance.new("Animation")
hal.AnimationId = "http://www.roblox.com/asset/?id=7747707560"
local har = Instance.new("Animation")
har.AnimationId = "http://www.roblox.com/asset/?id=7747710892"
local hurtAnimLeft = hithumanoid:LoadAnimation(hal)
local hurtAnimRight = hithumanoid:LoadAnimation(har)
local ranMath = math.random(1, 2)
if ranMath == 1 then
hurtAnimLeft:Play()
elseif ranMath == 2 then
hurtAnimRight:Play()
end
if config.CanSeverLimbs.Value == true then
if result.Instance.name == "Left Arm" or result.Instance.name == "LArmGore" then
LimbHandler.DamageLimb(hithumanoid.Parent, "Left Arm", LimbDamage * config.LArmMulti.Value)
elseif result.Instance.name == "Right Arm" or result.Instance.name == "RArmGore" then
LimbHandler.DamageLimb(hithumanoid.Parent, "Right Arm", LimbDamage * config.RArmMulti.Value)
elseif result.Instance.name == "Left Leg" or result.Instance.name == "LLegGore" then
LimbHandler.DamageLimb(hithumanoid.Parent, "Left Leg", LimbDamage * config.LLegMulti.Value)
elseif result.Instance.name == "Right Leg" or result.Instance.name == "RLegGore" then
LimbHandler.DamageLimb(hithumanoid.Parent, "Right Leg", LimbDamage * config.RLegMulti.Value)
elseif result.Instance.name == "Head" or result.Instance.name == "HeadGore" then
LimbHandler.DamageLimb(hithumanoid.Parent, "Head", LimbDamage * config.HeadMulti.Value)
end
end
wait(.5)
Debounce[hithumanoid] = false
local OldWalkSpeed = hithumanoid.WalkSpeed
hithumanoid.WalkSpeed = config.StaggerAmount
wait(config.StaggerTime)
hithumanoid.WalkSpeed = OldWalkSpeed
end
end)