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

Why wont this script work?

Asked by
iLegitus 130
10 years ago
-- 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

Log in to vote
1
Answered by
Merely 2122 Moderation Voter Community Moderator
10 years ago
  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
0
Thanks Merely iLegitus 130 — 10y
Ad

Answer this question