jtefurd
|
  |
| Joined: 01 May 2010 |
| Total Posts: 952 |
|
|
| 30 May 2015 11:24 PM |
Initially I made this all in a local gui, and I was told that you can't use the changed event in local guis. This was my solution and it ended up not working whatsoever. Background info: - The local script cloning the client-side script is in a frame w/in starter gui. - This script was meant for a red overlay when a player is hurt and it fades when the player nears full health. -The client-sided script's parent is the local script.
Local Script:
cloned = script.Script:Clone() cloned.Parent = game.Players.LocalPlayer.Character cloned.Disabled = false
Client-Sided Script:
char = script.Parent player = game.Players:GetPlayerFromCharacter(char) MaxHealth = char.Humanoid.MaxHealth;Health = char.Humanoid.Health char.Humanoid.Changed:connect(function() if Health < MaxHealth then player.PlayerGui.Health.BloodOverlay.BackgroundTransparency = 1-((.20*Health)/MaxHealth) elseif Health == MaxHealth then player.PlayerGui.Health.BloodOverlay.BackgroundTransparency = 1 end end) |
|
|
| Report Abuse |
|
|
|
| 30 May 2015 11:24 PM |
>>Initially I made this all in a local gui, and I was told that you can't use the changed event in local guis.
Whoever told you that is an idiot. |
|
|
| Report Abuse |
|
|
|
| 30 May 2015 11:26 PM |
| I agree with nQqzRYVpIKA5jLP |
|
|
| Report Abuse |
|
|
jtefurd
|
  |
| Joined: 01 May 2010 |
| Total Posts: 952 |
|
|
| 30 May 2015 11:26 PM |
| Crediting that information to ScriptingIntoTerror. XD |
|
|
| Report Abuse |
|
|
|
| 30 May 2015 11:27 PM |
>>It refuses to work. It's pretty impressive that you managed to create sentient life in only 10 lines of code. |
|
|
| Report Abuse |
|
|
jtefurd
|
  |
| Joined: 01 May 2010 |
| Total Posts: 952 |
|
|
| 30 May 2015 11:30 PM |
| I'm only attempting to manipulate a gui's transparency with and equation based on a player's health. :\ It shouldn't have to be complicated. |
|
|
| Report Abuse |
|
|
|
| 30 May 2015 11:38 PM |
| You do realize that localscripts and client-sided scripts are the same thing, right? And why the hell do you have the health script in the character? |
|
|
| Report Abuse |
|
|
jtefurd
|
  |
| Joined: 01 May 2010 |
| Total Posts: 952 |
|
|
| 30 May 2015 11:38 PM |
| He is my senpai so I trusted his decision, in the end however it still didn't work so yeah. :) |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 30 May 2015 11:46 PM |
local player = game.Players.LocalPlayer local char = player.Character local human = char.Humanoid
human.Changed:connect(function() if human.Health < human.MaxHealth then script.Parent.BackgroundTransparency = 1-((0.20*human.Health)/human.MaxHealth) elseif human.Health == human.MaxHealth then script.Parent.BackgroundTransparency = 1 end end)
|
|
|
| Report Abuse |
|
|
|
| 30 May 2015 11:49 PM |
local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:wait() local humanoid = character:WaitForChild("Humanoid") local bloodOverlay = script.Parent:WaitForChild("BloodOverlay")
function updateGui(health) bloodOverlay.BackgroundTransparency = health / humanoid.MaxHealth end
humanoid.HealthChanged:connect(updateGui) |
|
|
| Report Abuse |
|
|
jtefurd
|
  |
| Joined: 01 May 2010 |
| Total Posts: 952 |
|
|
| 31 May 2015 12:39 AM |
At last I made it work. I had to fix the equation using a line equation XD y=.8x+.27 I also used HealthChanged, thanks everyone who helped!
local player = game.Players.LocalPlayer local hum = player.Character:WaitForChild("Humanoid") MaxHealth = hum.MaxHealth hum.HealthChanged:connect(function(Health) if Health < MaxHealth then script.Parent.ImageTransparency = (.008*Health)+.27 elseif Health == MaxHealth then script.Parent.ImageTransparency = 1 end end) |
|
|
| Report Abuse |
|
|