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

StarterCharacter Interfering with Script?

Asked by 3 years ago

So, I have a problem where, when a player joins, it checks if they have a certain thing, and if they do, gives it to them, but, if they don't, checks if they have another thing. If they don't have anything, then ends the script. The middle is cut out because it's so big and I know works. Anyway, the script stops working on line 4. WaitForChild(). It might be because I have a StarterCharacter.

game.Players.PlayerAdded:Connect(function(plr)
    print("PlayerAdded")
    local Char = plr.Character
    Char:WaitForChild("Humanoid") --This is where the script stops working, even tho my character does load humanoid. Maybe because I have a StarterCharacter?
    print("CharAdded")

        --A big block of code that I know works is here
        --The functions for the armor are here

    wait(0.1)
        if plr.Armor["Oblivo Armor"].Value == true then
            print("ObTrue")
            ObArmor()
        elseif plr.Armor.Titanium.Value == true then
            print("KnTrue")
            KnArmor()
        elseif plr.Armor.Steel.Value == true then
            print("StTrue")
            StArmor()
        elseif plr.Armor.Iron.Value == true then
            print("IrTrue")
            IrArmor()
        else
            print("NoneTrue")
    end
end)

Help?

0
Did you define the functions? It looks like you made functions for the armor. Check the functions and the print to see if it's true. Dovydas1118 1495 — 3y
0
ok TheB4dComputer 100 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

Add a CharacterAdded event. You can't do the player.Character variable because it will be nil. The player is added first before the character. Sure the time difference might be slim, but it's a big difference.

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)

    end)
end)

Also have you checked if the player has those values to begin with? It seems you just put the values inside the player.

0
I tried Character added and I ran fine... but it said ObArmor was true and it isn't. Plus it didn't do anything. TheB4dComputer 100 — 3y
0
And yes, the values are there. TheB4dComputer 100 — 3y
0
I wish I could show the image, but it runs, says ob is true, and then doesn't do anything TheB4dComputer 100 — 3y
0
Nvm I found the error TheB4dComputer 100 — 3y
Ad

Answer this question