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

StarterCharacter Interfering with Script?

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?

2 comments

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.

0

ok

1 answer

✓ Accepted answer

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.

4 comments

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.

0

And yes, the values are there.

0

I wish I could show the image, but it runs, says ob is true, and then doesn't do anything

0

Nvm I found the error

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