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: "Healing brick" Not working as intended?

Previous Thread :: Next Thread 
jcarsonw2 is not online. jcarsonw2
Joined: 02 May 2012
Total Posts: 2115
17 Jun 2012 09:16 PM
Script:

Maker = Workspace.Player.Humanoid.Health

Workspace.Medikit:Touched:connect(function(hit)
while Maker < 100 do
Maker = Maker + 1
Wait(0.5)
Maker = Maker + 1
until Maker = 100
end
end)

I am pretty sure it has to do something with "Not storing the function" I am not quite to sure how to do such a thing, I haven't scripted in about a year and even then, I was a relatively bad scripter. Basically, this script is making you restore 2 points of health over a second, the function is wrong in some way, I am sure of it, and maybe the While loop...
Report Abuse
MassiveGman is not online. MassiveGman
Joined: 23 Jan 2011
Total Posts: 2019
17 Jun 2012 09:18 PM
Er.I think you used while wrong.
Try this:


Maker = Workspace.Player.Humanoid.Health

Workspace.Medikit:Touched:connect(function(hit)

if Maker < 100 then
Maker = Maker + 1
Wait(0.5)
Maker = Maker + 1
until Maker = 100
end
end)
Report Abuse
jcarsonw2 is not online. jcarsonw2
Joined: 02 May 2012
Total Posts: 2115
17 Jun 2012 09:18 PM
*Facepalm*

I forgot, the tables didn't work on the forums...

Maker = Workspace.Player.Humanoid.Health

Workspace.Medikit:Touched:connect(function(hit)
...while Maker < 100 do
...............Maker = Maker + 1
...............Wait(0.5)
...Maker = Maker + 1
...until Maker = 100
...end
end)
Report Abuse
MassiveGman is not online. MassiveGman
Joined: 23 Jan 2011
Total Posts: 2019
17 Jun 2012 09:20 PM
Is medikit a part or a model?
Report Abuse
MassiveGman is not online. MassiveGman
Joined: 23 Jan 2011
Total Posts: 2019
17 Jun 2012 09:21 PM
Also you forgot an even listener.


This goes at the end:

script.Parent.Touched:connect(hit)
Report Abuse
MassiveGman is not online. MassiveGman
Joined: 23 Jan 2011
Total Posts: 2019
17 Jun 2012 09:22 PM
game.Workspace.Medikit.Touched* sorry.
Report Abuse
jcarsonw2 is not online. jcarsonw2
Joined: 02 May 2012
Total Posts: 2115
17 Jun 2012 09:46 PM
Medikit is a brick, not a model, except the fact I got it from the tool box, but I doubt it counts as a model...? Thanks for the help.
Report Abuse
jcarsonw2 is not online. jcarsonw2
Joined: 02 May 2012
Total Posts: 2115
17 Jun 2012 10:26 PM
Script didn't work, here is the new script;

Maker = Workspace.Player.Humanoid.Health

Workspace.Medikit:Touched:connect(function(hit)

if Maker < 100 then
Maker = Maker + 1
Wait(0.5)
Maker = Maker + 1
until Maker = 100
end
end)

game.Workspace.Medikit.Touched:connect(hit)

--

Output: Workspace.Medikit.Script:3: function arguments expected near ':'
Report Abuse
Sehnsucht is not online. Sehnsucht
Joined: 10 Apr 2011
Total Posts: 990
17 Jun 2012 10:33 PM
Your script is a complete mess.

Workspace.Medikit:Touched:connect(function(hit)
if hit == nil or hit.Parent == nil then return end
local char = game.Players:GetPlayerFromCharacter(hit.Parent)
if char == nil then return end
local humanoid = char.Humanoid
if humanoid.Health < 100 then
repeat
humanoid.Health = humanoid.Health + 1
wait(0.2) -- 0.5 is not fast enough for a significant health increase
until humanoid.Health >= 100
end
end)
Report Abuse
Sehnsucht is not online. Sehnsucht
Joined: 10 Apr 2011
Total Posts: 990
17 Jun 2012 10:41 PM
Sorry, typo.

Workspace.Part.Touched:connect(function(hit)
if hit == nil or hit.Parent == nil then return end
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player == nil or player.Character == nil then return end
local humanoid = player.Character.Humanoid
if humanoid.Health < 100 and humanoid.Health > 0 then
repeat
humanoid.Health = humanoid.Health + 1
wait(0.2) -- 0.5 is not fast enough for a significant health increase
until humanoid.Health >= 100
end
end)
Report Abuse
jcarsonw2 is not online. jcarsonw2
Joined: 02 May 2012
Total Posts: 2115
17 Jun 2012 10:49 PM
Thank you so much for the script, I understand the mistakes I made and hopefully this will make me a better scripter!
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
17 Jun 2012 10:58 PM
Why not use TouchEnded?
Report Abuse
jcarsonw2 is not online. jcarsonw2
Joined: 02 May 2012
Total Posts: 2115
17 Jun 2012 11:00 PM
I... Have no idea what the function of TouchEnded is, can you explain?
Report Abuse
Sehnsucht is not online. Sehnsucht
Joined: 10 Apr 2011
Total Posts: 990
17 Jun 2012 11:00 PM
@nate
WEGIHEFAIWEAEIGWER THERE IS FINALLY A TOUCH ENDED EVENT?!?!!?!?!?! PLEASE DEAR GOD TELL ME YOU ARE NOT LYING TO ME I SWARE TO GODWERQ#R!@#R#
Report Abuse
Sehnsucht is not online. Sehnsucht
Joined: 10 Apr 2011
Total Posts: 990
17 Jun 2012 11:03 PM
@jcar, it's an event that is triggered when whatever is touching your object discontinues touching the object, so you could use it with your healing break to detect when the person gets off the healing pad, telling the script to stop giving health to the person.
Report Abuse
jcarsonw2 is not online. jcarsonw2
Joined: 02 May 2012
Total Posts: 2115
17 Jun 2012 11:04 PM
That seems extremely useful. Could I just plug in the TouchEnded into where the function is, and it would pretty much work the same way?
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
17 Jun 2012 11:11 PM
Yes, it was finally added a year ago.

   part.Touched:connect(function()
        part.Transparency=1
        part.TouchEnded:wait()
        part.Transparency=0
    end)
Report Abuse
Sehnsucht is not online. Sehnsucht
Joined: 10 Apr 2011
Total Posts: 990
17 Jun 2012 11:14 PM
You sir, have enlightened me.
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
17 Jun 2012 11:18 PM
    local touching=false

    part.Touched:connect(function(hit)
        if game.Players:GetPlayerFromCharacter(hit.Parent) then
            touching=true
            while wait(0.5) do
                if touching and hit.Parent.Humanoid.Health<=hit.Parent.Humanoid.MaxHealth then
                    hit.Parent.Humanoid.Health=hit.Parent.Humanoid.Health+10
                else
                    break
                end
            end
        end
    end)

    part.TouchEnded:connect(function()
        touching=false
    end)
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
17 Jun 2012 11:30 PM
Now that I look back at it, and remember, the roblox health gui is buggy, so if the health is 99, and you get the +10 health increase, you'll have 109 health (it'll get changed back to 100 because the maxhealth is 100, but the health gui won't be changed and will appear as if you have more than usual health.)

So go with this instead...

local touching=false

script.Parent.Touched:connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        touching=true
        local humanoid=hit.Parent.Humanoid
        while wait(0.5) do
            if touching and humanoid.Health<=humanoid.MaxHealth then
                humanoid.Health=humanoid.Health+(humanoid.Health+10>humanoid.MaxHealth and humanoid.MaxHealth-humanoid.Health or 10)
            else
                break
            end
        end
    end
end)

script.Parent.TouchEnded:connect(function()
    touching=false
end)
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