Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

If statement doesn't run at all?

function Slow(victim, duration, potency)
				print'attempted to apply slow 2'
				if victim and victim.Parent and victim.Parent.Head and victim.Parent.Torso then
					if victim and victim.Parent and victim.Parent:FindFirstChild('Humanoid') then
						print'found humanoid'
						local humanoid = victim.Parent.Humanoid
						print'debug'
						if humanoid.Walkspeed > potency then
							print'greater than potency'
							humanoid.Walkspeed = humanoid.Walkspeed - potency
							wait(duration)
							humanoid.Walkspeed = humanoid.Walkspeed + potency
						else
							print'less'
							local original = humanoid.Walkspeed
							humanoid.Walkspeed = 0
							wait(duration)
							humanoid.Walkspeed = humanoid.Walkspeed + original
						end
					end
				end
			end

Everything prints except 'greater than potency' or 'less'. Because it's an else and not an else if, im inclined to believe its not running at all, or it'd print 'less'. Any idea why it stops?

1 answer

✓ Accepted answer

Your problem was quite simple, since lua is case-sensitive, you'd have to spell Walkspeed to WalkSpeed.

function Slow(victim, duration, potency)
                print'attempted to apply slow 2'
                if victim and victim.Parent and victim.Parent.Head and victim.Parent.Torso then
                    if victim and victim.Parent and victim.Parent:FindFirstChild('Humanoid') then
                        print'found humanoid'
                        local humanoid = victim.Parent.Humanoid
                        print'debug'
                        if humanoid.WalkSpeed > potency then
                            print'greater than potency'
                            humanoid.WalkSpeed = humanoid.WalkSpeed - potency
                            wait(duration)
                            humanoid.WalkSpeed = humanoid.WalkSpeed + potency
                        else
                            print'less'
                            local original = humanoid.WalkSpeed
                            humanoid.WalkSpeed = 0
                            wait(duration)
                            humanoid.WalkSpeed = humanoid.WalkSpeed + original
                        end
                    end
                end
            end

This discussion is preserved as it was. New answers, comments, and votes are closed.