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

Why wont this script work?

-- iLegimate --



-- Functions --
function choseASSASIN()
    if game.Players.NumPlayers>0 then
     local chosen=game.Players:GetPlayers()[math.random(1,game.Players.NumPlayers)]
	 chosen.Character.Humanoid.MaxHealth = 2000
	 chosen.Character.Humanoid.Health = 2000
	 chosen.Character.Humanoid.WalkSpeed = 20
 	-- ADD THE SHIRT TEMPLATE AND PANTS TEMPLATE (BELOW) --
        if chosen.Character:findFirstChild("Shirt") then
            chosen.Character.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=169491383"
		            else
			s = Instance.new("Shirt", chosen.Character)
			s.ShirtTemplate = "http://www.roblox.com/asset/?id=169491383"
			
			
end

			if chosen.Character:findFirstChild("Pants") then
			chosen.Character.Pants.PantsTemplate = "http://www.roblox.com/asset/?id=" 
			else
				p = Instance.new("Pants", chosen.Character)
			p.Name = "Pants"
			p.PantsTemplate = "http://www.roblox.com/asset/?id="
end
end


end


wait(5)
choseASSASIN()

It works in test solo,But when i start a server it doesnt work at all. Please help.

1 answer

✓ Accepted answer
  1. You're assuming that the player's Character is not nil and the Character has a Humanoid. You should be using WaitForChild.

  2. This script will most likely run before any players join the game. The server exists usually for 10-15 seconds before a player gets the chance to join. If that happens, of course it won't work.

Try something like this on line 7:

while game.Players.NumPlayers < 1 do
	game.Players.PlayerAdded:wait()
end

1 comment

0

Thanks Merely

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