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

Functions not running when I call them?

Asked by 3 years ago

This question has been solved by the original poster.

I've once more come here to ask about my fall damage. the problem I'm having now is that I want it so if a command is run it puts you on a list that makes it so you no longer have fall damage. I have the command system working, but my function doesn't run when it should.

local HeightRequired = 10
local DamageScale = 2.5 
local exluded = {}
local new = script.New

script.New.Changed:Connect(function()
    for index = 1, #exluded, 1 do                   
        if new.Value ~= exluded[index] and index == #exluded then
            for i, plr in pairs(game.Players:GetPlayers()) do
                if new.Value == plr.Name then
                    table.insert(exluded, #exluded + 1, new.Value)
                    print("added "..new.Value.." to exluded list")
                    new.Value = ""
                    break
                end
            end
        elseif new.Value == exluded[index] then
            print(new.Value.." is already on exlude list")
            break
        end
    end 
end)

game.Players.PlayerAdded: Connect(function(Player)
    Player.CharacterAdded: Connect(function(Character)
        local HumanoidRootPart = Character:WaitForChild('HumanoidRootPart')
        local Humanoid = Character:WaitForChild('Humanoid')

        local StartJump = nil

        Humanoid.FreeFalling:Connect(function(Active)
            if Active then
                StartJump = HumanoidRootPart.Position.Y
            else
                local JumpHeight = StartJump - HumanoidRootPart.Position.Y

                if JumpHeight > HeightRequired and Humanoid.FloorMaterial ~= Enum.Material.SmoothPlastic then
                    for index = 1, #exluded, 1 do
                        if Humanoid.Parent.Name ~= exluded[index] and index == #exluded then
                            Humanoid:TakeDamage((JumpHeight - HeightRequired)*DamageScale)
                            break
                        elseif Humanoid.Parent.Name == exluded[index] then
                            break
                        end
                    end             
                end
            end
        end)
    end)
end)

I can't seem to find the error in this mainly because nothing comes up in the output, my fall damage just stops working even if I'm not on the list.

as always any help is appreciated.

0
So wait, is New a value? Nckripted 580 — 3y
0
Never mind, that was a stupid question. What I meant to ask was what exactly is being passed through the Active parameter? I don't have good experience with this event, so I would need to know how it works. Nckripted 580 — 3y
0
Never mind, that was a stupid question. What I meant to ask was what exactly is being passed through the Active parameter? I don't have good experience with this event, so I would need to know how it works. Nckripted 580 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

I managed to fix the issue, it was simply solved by adding a dummy value into the table so that the for loops wouldn't break.

0
Great! Nckripted 580 — 3y
Ad

Answer this question