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: I connected a function to some events

Previous Thread :: Next Thread 
robocu3 is not online. 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 is not online. robocu3
Joined: 13 Mar 2009
Total Posts: 6485
30 Jun 2014 08:53 AM
bump
-=Robo=-
Report Abuse
Infocus is not online. 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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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 is not online. robocu3
Joined: 13 Mar 2009
Total Posts: 6485
30 Jun 2014 09:30 AM
That's what I was doing. :/
-=Robo=-
Report Abuse
robocu3 is not online. 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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
30 Jun 2014 09:33 AM
Oh, we'll then.
Report Abuse
robocu3 is not online. 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 is not online. 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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
30 Jun 2014 11:28 AM
Well*


It was a LocalScript XD
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