generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: PlayerAdded script question

Previous Thread :: Next Thread 
Tonitoni is not online. Tonitoni
Joined: 14 Mar 2009
Total Posts: 6429
20 Apr 2014 10:00 AM
I have some NPC soldiers who shoot at everyone who isn't infected. They find out if said person is infected by checking for a BoolValue named infected. Since I don't want the AI's to shoot the player until he does something, I figured I'd add the Infected BoolValue to the player, as soon as he enters.

Like this:
game.Players.PlayerAdded:connect(function(player)
print("PlayerAdded script is running")
local Cannotkill = Instance.new("BoolValue")
print("Created the boolvalue")
Cannotkill.Name = "Infected"
print("Changed its name")
Cannotkill.Value = true
print("Changed its value")
Cannotkill.Parent = player
print("Gave it to the player")
end)

for _, player in pairs(game.Players:GetPlayers()) do
PlayerAdded(player) -- Use your player added handling function here.
end

All of the above prints, but the BoolValue isn't added to the player. Help? Does PlayerAdded maybe get the player in the Players directory, not in Workspace? If so, how do I find the one in Workspace?
Also I don't quite know what the last 3 lines do, but wiki told me to add them when testing in play solo. (Which I am doing)
Report Abuse
NumeriusValerius is not online. NumeriusValerius
Joined: 28 Dec 2009
Total Posts: 3089
20 Apr 2014 10:02 AM
PlayerAdded = (function(player)
local Cannotkill = Instance.new("BoolValue",player)
Cannotkill.Name = "Infected"
Cannotkill.Value = true
end)

game.Players.PlayerAdded:connect(PlayerAdded)
for _, player in pairs(game.Players:GetPlayers()) do
PlayerAdded(player) -- Use your player added handling function here.
end
Report Abuse
Tonitoni is not online. Tonitoni
Joined: 14 Mar 2009
Total Posts: 6429
20 Apr 2014 10:04 AM
Just checked, and the infected BoolValue got added to the player in the Players directory, not the player model in workspace. Is there a function I can use that returns the player model every time the player spawns?

I figured I could just have a touch event on the spawn point, but I don't think that is the best way...
Report Abuse
NumeriusValerius is not online. NumeriusValerius
Joined: 28 Dec 2009
Total Posts: 3089
20 Apr 2014 10:05 AM
PlayerAdded = (function(player)
player.CharacterAdded:connect(function(character)
local Cannotkill = Instance.new("BoolValue",character)
Cannotkill.Name = "Infected"
Cannotkill.Value = true
end)
end)

game.Players.PlayerAdded:connect(PlayerAdded)
for _, player in pairs(game.Players:GetPlayers()) do
PlayerAdded(player) -- Use your player added handling function here.
end
Report Abuse
Tonitoni is not online. Tonitoni
Joined: 14 Mar 2009
Total Posts: 6429
20 Apr 2014 10:11 AM
Thanks NumeriusValerius! Worked flawlessly :)
Report Abuse
NumeriusValerius is not online. NumeriusValerius
Joined: 28 Dec 2009
Total Posts: 3089
20 Apr 2014 10:11 AM
No problem.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image