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 » Scripters
Home Search
 

Re: Script works in studio but

Previous Thread :: Next Thread 
electricpretzel0 is not online. electricpretzel0
Joined: 30 Sep 2008
Total Posts: 1278
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
electricpretzel0 is not online. electricpretzel0
Joined: 30 Sep 2008
Total Posts: 1278
31 Mar 2016 07:39 PM
omg nobody looked at this come on
Report Abuse
LuaLlama is not online. 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
electricpretzel0 is not online. electricpretzel0
Joined: 30 Sep 2008
Total Posts: 1278
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 is not online. LuaLlama
Joined: 25 Jan 2014
Total Posts: 1123
31 Mar 2016 07:47 PM
press F9 and post the error
Report Abuse
electricpretzel0 is not online. electricpretzel0
Joined: 30 Sep 2008
Total Posts: 1278
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
KeiRoMultiverse is not online. KeiRoMultiverse
Joined: 16 Aug 2013
Total Posts: 1896
31 Mar 2016 08:13 PM
Delete the "local" in "local health."
Report Abuse
KeiRoMultiverse is not online. KeiRoMultiverse
Joined: 16 Aug 2013
Total Posts: 1896
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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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 is not online. Crimsonal
Joined: 23 Apr 2011
Total Posts: 1795
31 Mar 2016 09:10 PM
using local variables make ur code faster
Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
31 Mar 2016 09:11 PM
ya barely
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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
KeiRoMultiverse is not online. KeiRoMultiverse
Joined: 16 Aug 2013
Total Posts: 1896
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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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
KeiRoMultiverse is not online. KeiRoMultiverse
Joined: 16 Aug 2013
Total Posts: 1896
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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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
KeiRoMultiverse is not online. KeiRoMultiverse
Joined: 16 Aug 2013
Total Posts: 1896
31 Mar 2016 09:26 PM
Thanks for the help.
Report Abuse
electricpretzel0 is not online. electricpretzel0
Joined: 30 Sep 2008
Total Posts: 1278
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
KeiRoMultiverse is not online. KeiRoMultiverse
Joined: 16 Aug 2013
Total Posts: 1896
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
electricpretzel0 is not online. electricpretzel0
Joined: 30 Sep 2008
Total Posts: 1278
01 Apr 2016 08:58 AM
anyone have an idea?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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