robocu3
|
  |
| Joined: 13 Mar 2009 |
| Total Posts: 6485 |
|
|
| 30 Jun 2014 08:30 AM |
But when they fire, the functions don't execute. I'm not sure what I'm doing wrong. local function updatePlayers() print("UpdatePlayers fired.") players = game.Players:GetPlayers() local pos = 0 for _, search in pairs(script.Parent.UI:GetChildren()) do if string.match(search.Name, "Player_") then search:Destroy() end end for index, player in pairs(players) do if player.Name ~= MainPlayer.Name and player.Character and MainPlayer.TeamColor ~= "Really blue" then if player.TeamColor == MainPlayer.TeamColor then local positionFactor = .15 * pos pos = pos + 1 local PlayerHUD = TeamMemberDisplay:Clone() PlayerHUD.Name = "Player_"..player.Name.."_Health" PlayerHUD.Parent = script.Parent.UI PlayerHUD.PlayerName.Text = player.Name PlayerHUD.Position = UDim2.new(0.05 + positionFactor, 0, 0.865, 0) local function setHealthForPlayer() if player.Character then local HealthyColor = endColor:lerp(startColor, player.Character.Humanoid.Health/100) PlayerHUD.HealthBacking.HealthBar.BackgroundColor3 = Color3.new(HealthyColor.x/255, HealthyColor.y/255, HealthyColor.z/255) PlayerHUD.HealthBacking.HealthAmount.TextStrokeColor3 = Color3.new(HealthyColor.x/255, HealthyColor.y/255, HealthyColor.z/255) PlayerHUD.HealthBacking.HealthBar.Size = UDim2.new(player.Character.Humanoid.Health/100,0,1,0) PlayerHUD.HealthBacking.HealthAmount.Text = "+"..tostring(math.floor(player.Character.Humanoid.Health)) end end setHealthForPlayer() player.Character.Humanoid.Changed:connect(setHealthForPlayer) end end end end
^that's the attempted function, which runs perfectly on it's own
here's where things stop working; game.Players.PlayerAdded:connect(updatePlayers) game.Players.PlayerRemoving:connect(updatePlayers) for _, player in pairs(game.Players:GetPlayers()) do player.CharacterAdded:connect(updatePlayers) player.CharacterRemoving:connect(updatePlayers) end or supposedly. i ran this in a test server and playeradded didn't seem to fire? -=Robo=- |
|
|
| Report Abuse |
|
|
robocu3
|
  |
| Joined: 13 Mar 2009 |
| Total Posts: 6485 |
|
| |
|
Infocus
|
  |
| Joined: 28 Apr 2011 |
| Total Posts: 8022 |
|
|
| 30 Jun 2014 09:16 AM |
game.Players.PlayerAdded:connect(function(plyr) updatePlayers() end)
You're putting your function where the events argument is supposed to be. |
|
|
| Report Abuse |
|
|
|
| 30 Jun 2014 09:20 AM |
PlayerAdded will not fire when testing Play Solo
Instead, just start a server from studio.
Test -> Start Server |
|
|
| Report Abuse |
|
|
robocu3
|
  |
| Joined: 13 Mar 2009 |
| Total Posts: 6485 |
|
|
| 30 Jun 2014 09:30 AM |
That's what I was doing. :/ -=Robo=- |
|
|
| Report Abuse |
|
|
robocu3
|
  |
| Joined: 13 Mar 2009 |
| Total Posts: 6485 |
|
|
| 30 Jun 2014 09:32 AM |
and @Infocus that didn't really... make sense >.> lol You're creating an anonymous function to call a function, that's inefficient and pointless and I don't need the plyr argument. -=Robo=- |
|
|
| Report Abuse |
|
|
| |
|
robocu3
|
  |
| Joined: 13 Mar 2009 |
| Total Posts: 6485 |
|
|
| 30 Jun 2014 09:52 AM |
;-; i don't understand why it's not connecting. -=Robo=- |
|
|
| Report Abuse |
|
|
robocu3
|
  |
| Joined: 13 Mar 2009 |
| Total Posts: 6485 |
|
|
| 30 Jun 2014 10:09 AM |
Of course it's because you can't use PlayerAdded in a local script. *facepalm* stupid mistakes always get the best of me -=Robo=- |
|
|
| Report Abuse |
|
|
|
| 30 Jun 2014 11:28 AM |
Well*
It was a LocalScript XD |
|
|
| Report Abuse |
|
|