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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 14 Mar 2009 |
| Total Posts: 6429 |
|
|
| 20 Apr 2014 10:11 AM |
| Thanks NumeriusValerius! Worked flawlessly :) |
|
|
| Report Abuse |
|
|
| |
|