I’m attempting to use a module script to make stun. In which I’ll check for the humanoid being stunned and the duration, but I’m trying to set the jump power and the walk speed to 0 when the stun occurs.
function Mod.stun(hum, dur)
local walkspeed = hum.WalkSpeed
local jumppower = hum.JumpPower
walkspeed = 0
jumppower = 0
wait(dur)
walkspeed = 14
jumppower = 50.145
end
return Mod
But I was able to still move.
i tried to set it up as
function Mod.stun(hum, dur)
hum.WalkSpeed = 0
hum.JumpPower = 0
wait(dur)
hum.WalkSpeed = 14
hum.JumpPower = 50.145
end
return Mod
local hitbox = script.Parent
local punchsfx = game.ReplicatedStorage.Punch:Clone()
local stunanim = game.ReplicatedStorage.StunAnim
local stunmod = require(game.ReplicatedStorage.Stun)
punchsfx.Parent = character
hitbox.Touched:Once(function(hit)
if hit.Parent ~= character then
local humanoid = hit.Parent:FindFirstChild("Humanoid")
local Animator = humanoid:FindFirstChild("Animator")
local stunanimate = Animator:LoadAnimation(stunanim)
if humanoid then
humanoid:TakeDamage(10)
print(humanoid.Health)
stunanimate:Play()
punchsfx:Play()
stunmod.stun(humanoid, 1.5)
stunanimate:Stop()
end
end
end)
``
What you are a doing does not seem to update the hum.JumpPower and hum.WalkSpeed property. The references to those initialized in the first two lines of the function are irrelevant as they are not referencing a pointer, but rather a primitive datatype. In other words, if you update the variable you are updating a variable that has a copied value from the hum.WalkSpeed and hum.JumpPower property. When you set walkspeed to 0, it is only updating the value of the new variable and not hum.WalkSpeed. A corrected form for this would be:
function Mod.stun(hum, dur)
local walkspeed = hum.WalkSpeed
local jumppower = hum.JumpPower
hum.WalkSpeed = 0
hum.JumpPower = 0
wait(dur)
hum.WalkSpeed = 14
hum.JumpPower = 50.145
end
return Mod
If you want to revert it to the previous data you could do:
function Mod.stun(hum, dur)
local walkspeed = hum.WalkSpeed
local jumppower = hum.JumpPower
hum.WalkSpeed = 0
hum.JumpPower = 0
wait(dur)
hum.WalkSpeed = walkspeed
hum.JumpPower = jumppower
end
return Mod
Reminding you once again that storing an integer in a variable does not mean that any changes to that variable will reflect on the property it was initialized from. For example, primitive data types like string, boolean, and numbers cannot be referenced like an Instance would.