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

What part of this script am i doing wrong?

Asked by 8 years ago

Well, basically, when i was testing my script, it worked, except for one part. ( This is a part of a script in which it checks a match for the GUI in the GUI folder thing and the player in which the GUI is named after. ) I believe i'm doing this a bit wrong, since i'm still learning about functions, return, etc. BTW, the script is in PlayerGui

Anyways, here's the script.

function GetPlayersFromGui(GUI)
    for i = 1, #GUI do
        GUI[GUI[i]] = true
    end
end


local localplayer = script.Parent.Parent

function Checkingfunc()
    local GUIers = GetPlayersFromGui(localplayer.PlayerGui.HealthBar:GetChildren())
    if GUIers ~= nil then
    for i, player in ipairs (game.Players:GetPlayers()) do
            local match = GUIers[player.Name]
            if not match then

                print ("Chacked")
                grabplayers(localplayer)
                return 

            end
    end
    end
end




while true do
    Checkingfunc()
        print("WTD works!")
    wait(5)
end

When i test the script, Checkingfunc() isn't working (Demonstrated by "Chacked" not printing in the output), but when the *while true do * has been triggered, it prints perfectly.

If there's any details, please comment!

0
Try changing match to 'local match = GUIers:FindFirstChild(player.Name)' TheDeadlyPanther 2460 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

You need to be using the return keyword. On line 3, you've written GUI[GUI[i]] = true,are you sure that's what you want to be doing? I don't think you've gotten the hang of scope, tables, or how functions work.

GUIers is equal to that function. But the function isn't returning anything, so GUIers is basically nil.

Also, it's redundant because all it's doing is making a list of everything in there. If you ignore the function then your code works. You're just checking to see if each player's name can be found if you use it to look inside the health bar guis. You don't need a function that just gives you a list of everybody.

Why are you returning on line 19 anyway? Do you want to stop checking as soon as you've found 1 bad egg? Not really sure why you'd want to do that, but if you change your mind i've indicated in the fixed code below that you can remove it.

local localplayer = script.Parent.Parent

function Checkingfunc()
    local GUIers = localplayer.PlayerGui.HealthBar:GetChildren()
    for i, player in ipairs (game.Players:GetPlayers()) do
            local match = GUIers[player.Name]
            if not match then
                print ("Chacked")
                grabplayers(localplayer)
                return --remove if you want to check even after there's 1 bad match
            end
    end
end

while true do
    Checkingfunc()
        print("WTD works!")
    wait(5)
end
Ad

Answer this question