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

2 Functions possibly not working?

Asked by 8 years ago

I am not sure what is exactly wrong with my kill script. I have tried many varitions of it though for some reason anything I do with FindFirstChild never works. I want it so that if your in the group and your rank 2 it allows you in but if not then it kills you.

script.Parent.Touched:connect(function(hit)
game.Players.PlayerAdded:connect(function(Player)
    if Player:GetRankInGroup(2758901) == 2 then
        print("Good")
    else
       if hit.Parent:FindFirstChild("Humanoid") >= true then
    hit.Parent.Torso:Remove()
end
    end
end)
end)

The console shows nothing and i am guessing that its my functions.

2 answers

Log in to vote
1
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

The playeradded event won't start running until after it's been touched, but for it to be touched by a character, a player already has to be present, right? You should use GetPlayerFromCharacter instead.

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if Player then
            if Player:GetRankInGroup(2758901) == 2 then
                print("Good")
            else
                hit.Parent.Torso:Remove() -- Moved the check for humanoid up.
            end
        end
    end
end)
Ad
Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

Nice try, but you never define a player variable, nor check if it was a Player!

script.Parent.Touched:connect(function(hit)
    local p = game.Players:GetPlayerFromCharacter(hit.Parent)
    if p then
        if p:GetRankInGroup(2758901) == 2 then
            print("Good")
        else
            p.Character:BreakJoints() -- Better way to kill
        end
    end
end)

Answer this question