Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Humanoid.Running is not working right, any other way?

Asked by
FiredDusk 1466 Moderation Voter
7 years ago

So, what I am trying to do is make a "The Flash" script. So far what it does is, makes a few parts when I move but then stops making parts. I want to continuously place parts as I am moving, it just makes a few.

function showLightning(on,char)
    if on == true then
        local part = Instance.new('Part')
        part.Anchored = true
        part.CanCollide = false
        part.Size = Vector3.new(1,4,3)
        part.BrickColor = BrickColor.new('Bright yellow')
        part.Transparency = .6
        part.CFrame = char.Torso.CFrame * CFrame.new(0,0,3)
        part.Parent = workspace
    else
        print'a'
    end
end

game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(char)
        char:FindFirstChild('Humanoid').Running:connect(function(speed)
            if speed >= 4 then
                showLightning(true, char)
            elseif speed <= 1 then
                showLightning(false, char)
            end
        end)
    end)
end)

1 answer

Log in to vote
1
Answered by
cabbler 1942 Moderation Voter
7 years ago

Humanoid.Running only fires when your speed changes so it's not the best way. You should make your own loop. You can simply get the speed yourself using a velocity magnitude. Try to keep the wait time low.

game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(char)
        local head = char:WaitForChild('Head')
        while wait(1/10) do
            local speed = head.Velocity.Magnitude
            if speed >=4 then
                showLightning(true, char)
            elseif speed <= 1 then
                showLightning(false, char)
            end
        end
    end)
end)
0
Why do wait(1/10) and not wait(.1)? FiredDusk 1466 — 7y
0
They are equal. cabbler 1942 — 7y
Ad

Answer this question