|
| 31 Mar 2016 07:30 PM |
Hi guys. I'm fed up with ROBLOX.
I have a script that works perfectly in studio play solo mode, but when I try it in a server, It does not run AT ALLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL. Why ;-; |
|
|
| Report Abuse |
|
|
|
| 31 Mar 2016 07:39 PM |
| omg nobody looked at this come on |
|
|
| Report Abuse |
|
|
LuaLlama
|
  |
| Joined: 25 Jan 2014 |
| Total Posts: 1123 |
|
|
| 31 Mar 2016 07:41 PM |
| If it's in a local script change it to server, if not, change it to local. |
|
|
| Report Abuse |
|
|
|
| 31 Mar 2016 07:45 PM |
In a regular script
sp=script.Parent.Humanoid brick=sp.Parent.Head flashing=sp.Flashing local health=sp.Health
sp.Changed:connect(function() if health~=sp.Health then print("updated "..health) health=sp.Health if sp.Health/sp.MaxHealth>.9 then print("updated green") brick.BrickColor=BrickColor.new("Bright green") elseif sp.Health/sp.MaxHealth>.6 then print("updated yellon") brick.BrickColor=BrickColor.new("Bright yellow") elseif sp.Health/sp.MaxHealth>.25 then print("updated orage") brick.BrickColor=BrickColor.new("Bright orange") elseif sp.Health/sp.MaxHealth>.05 then print("updated red") brick.BrickColor=BrickColor.new("Bright red") elseif sp.Health/sp.MaxHealth>0 then flashing.Value=true sp.Flash.Disabled=false end end end)
|
|
|
| Report Abuse |
|
|
LuaLlama
|
  |
| Joined: 25 Jan 2014 |
| Total Posts: 1123 |
|
|
| 31 Mar 2016 07:47 PM |
press F9 and post the error
|
|
|
| Report Abuse |
|
|
|
| 31 Mar 2016 07:51 PM |
| There's absolutely no error or anything, The script is not disabled too. I dont get IT!!!! |
|
|
| Report Abuse |
|
|
|
| 31 Mar 2016 08:13 PM |
| Delete the "local" in "local health." |
|
|
| Report Abuse |
|
|
|
| 31 Mar 2016 08:54 PM |
I looked deeper at your script and changed some stuff. It works perfect now.
Humanoids have a HealthChanged event, so it's easier. I changed the arguments for your health colors, it, for some reason, works better like this.
sp=script.Parent:WaitForChild("Humanoid") brick=script.Parent:WaitForChild("Head") flashing=sp:WaitForChild("Flashing")
sp.HealthChanged:connect(function(health) print("HealthChanded") if sp.Health/sp.MaxHealth <=1 and sp.Health/sp.MaxHealth>.6 then print("updated green") brick.BrickColor=BrickColor.new("Bright green") elseif sp.Health/sp.MaxHealth <=.6 and sp.Health/sp.MaxHealth>.25 then print("updated yellon") brick.BrickColor=BrickColor.new("Bright yellow") elseif sp.Health/sp.MaxHealth <=.25 and sp.Health/sp.MaxHealth>.1 then print("updated orage") brick.BrickColor=BrickColor.new("Bright orange") elseif sp.Health/sp.MaxHealth <=.1 and sp.Health/sp.MaxHealth>.05 then print("updated red") brick.BrickColor=BrickColor.new("Bright red") elseif sp.Health/sp.MaxHealth <=.05 flashing.Value=true sp.Flash.Disabled=false end end) |
|
|
| Report Abuse |
|
|
|
| 31 Mar 2016 09:07 PM |
'Delete the "local" in "local health."' No. Always use local variables unless you have a good reason to not use them. And no, Kei, not understanding scopes and local variables is not a good reason. |
|
|
| Report Abuse |
|
|
Crimsonal
|
  |
| Joined: 23 Apr 2011 |
| Total Posts: 1795 |
|
|
| 31 Mar 2016 09:10 PM |
| using local variables make ur code faster |
|
|
| Report Abuse |
|
|
| |
|
|
| 31 Mar 2016 09:12 PM |
Actually, of optimizations you could make, local variables is one of the more significant ones, esp in loops.
And seriously, I can't think of a language that doesn't use local variables by default anyways, so it's a good practice. |
|
|
| Report Abuse |
|
|
|
| 31 Mar 2016 09:15 PM |
| Good to know, I've always been taught to only use local when they're to be contained in their own thread. Guess I've been misinformed. |
|
|
| Report Abuse |
|
|
|
| 31 Mar 2016 09:20 PM |
Well, it's kind of like that, if I understand that statement right.
They only work in their own scope and sub-scopes. If you need to use them outside, declare them outside:
local TestVar = 0 function Test() TestVar = TestVar + 1 print(TestVar) -- Increments by 1 each time. end
---------------------------
function Test() local TestVar = 0 TestVar = TestVar + 1 print(TestVar) -- Prints 1 each time. end |
|
|
| Report Abuse |
|
|
|
| 31 Mar 2016 09:21 PM |
| So, based con that, I'm guessing the whole script right from the beginning is a scope all its own. Is that close to right? |
|
|
| Report Abuse |
|
|
|
| 31 Mar 2016 09:25 PM |
Yes, it is. Flux might correct me on a minor technicality that is only discernible from the code behind Lua, but otherwise yes.
I don't know what it is called, but personally I would prefer "Top level scope". |
|
|
| Report Abuse |
|
|
| |
|
|
| 01 Apr 2016 08:14 AM |
Thanks, but this still only works in STUDIO, not in a server..
sp=script.Parent:WaitForChild("Humanoid") brick=script.Parent:WaitForChild("Head") flashing=sp:WaitForChild("Flashing")
sp.HealthChanged:connect(function(health) print("HealthChanded") script.Parent.Name="The Big Cheese "..sp.Health.."/"..sp.MaxHealth if sp.Health/sp.MaxHealth <=1 and sp.Health/sp.MaxHealth>.8 then print("updated green") brick.BrickColor=BrickColor.new("Bright green") elseif sp.Health/sp.MaxHealth <=.8 and sp.Health/sp.MaxHealth>.5 then print("updated yellon") brick.BrickColor=BrickColor.new("Bright yellow") elseif sp.Health/sp.MaxHealth <=.5 and sp.Health/sp.MaxHealth>.25 then print("updated orage") brick.BrickColor=BrickColor.new("Bright orange") elseif sp.Health/sp.MaxHealth <=.25 and sp.Health/sp.MaxHealth>.05 then print("updated red") brick.BrickColor=BrickColor.new("Bright red") elseif sp.Health/sp.MaxHealth <=.05 then flashing.Value=true sp.Flash.Disabled=false end end)
|
|
|
| Report Abuse |
|
|
|
| 01 Apr 2016 08:27 AM |
Really? Because I actually used the script and it works fine.
http://www.roblox.com/games/384643396/TestPlaceThree
^ See? It works.
Is there maybe anything else in the script that might cause it to not work? What script are you using to put the health script in the character? |
|
|
| Report Abuse |
|
|
| |
|