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: Detecting if a certain player is on fire

Previous Thread :: Next Thread 
broadbandrob is not online. broadbandrob
Joined: 09 May 2017
Total Posts: 9
31 May 2017 07:59 PM
I am developing my first Roblox space and am getting familiar with the framework and classes. Normally a C# guy.

Anyways, I thought I would use the ServerScriptService to iterate through all the players to determine if any players were on fire. If the player is on fire I want to reduce their health until they put the fire out. Admittedly the code could be cleaned up some, iterating through parts else if statements etc., but it is just an exercise to learn the character models.

I think the issue is with this line:
if(limb:FindFirstChild("Fire"))

I have debugged and expanded the children of the limbs to find parts. Do I need to expand further into the parts themselves to detect the Fire object? Would there be some other variable or name?

Thanks in advance for any help.




Here is what I have so far:

--check players
for i, player in ipairs(game.Players:GetPlayers()) do
local fire = false
--if fire then
if player.Character then
local localPlayer = game.Players:GetPlayerFromCharacter(player.Character)
local hum = player.Character:FindFirstChild('Humanoid')

if(player.Character["LeftLowerArm"]) then
local limb = player.Character["LeftLowerArm"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end

if(player.Character["LeftUpperArm"]) then
local limb = player.Character["LeftUpperArm"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end

if(player.Character["RightLowerArm"]) then
local limb = player.Character["RightLowerArm"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end

if(player.Character["RightUpperArm"]) then
local limb = player.Character["RightUpperArm"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end

if(player.Character["Pants"]) then
local limb = player.Character["Pants"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end


if(player.Character["LeftLowerLeg"]) then
local limb = player.Character["LeftLowerLeg"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end

if(player.Character["LeftUpperLeg"]) then
local limb = player.Character["LeftUpperLeg"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end

if(player.Character["RightLowerLeg"]) then
local limb = player.Character["RightLowerLeg"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end

if(player.Character["RightUpperLeg"]) then
local limb = player.Character["RightUpperLeg"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end

if################################hen
local limb = pl############################ if(limb:FindFirstChild("Fire")) then
fire = true
end
end

if(player.Character["RightFoot"]) then
local limb = player.Character["RightFoot"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end

if(player.Character["LeftHand"]) then
local limb = player.Character["LeftHand"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end

if(player.Character["RightHand"]) then
local limb = player.Character["RightHand"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end

if(player.Character["LowerTorso"]) then
local limb = player.Character["LowerTorso"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end

if(player.Character["UpperTorso"]) then
local limb = player.Character["UpperTorso"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end


if(player.Character["Head"]) then
local limb = player.Character["Head"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end


if(player.Character["Shirt"]) then
local limb = player.Character["Shirt"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end


if(fire)then
hum.Health = hum.Health - 1
end

end
-- end
end
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
31 May 2017 08:01 PM
B
R
U
H

while character:findFirstChildOfClass("Fire") do
--burn damage
end
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
31 May 2017 08:01 PM
I highly recommend cleaning up your code more if you come here again. It's much more appealing and much more likely to get you help.

Anyway, on what basis is the code being ran? Is that the entire script, or do you have it looped/connected to an event?


Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
31 May 2017 08:01 PM
"while character:findFirstChildOfClass("Fire") do
--burn damage
end"

And if they don't have fire/stop burning, it will stop working.


Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
31 May 2017 08:02 PM
ik i meant thats what u have to use or something similar to it inside of checking like every little part for fire lmao

and also u have to bind that to an event
Report Abuse
broadbandrob is not online. broadbandrob
Joined: 09 May 2017
Total Posts: 9
31 May 2017 09:09 PM
First off, thanks for the quick replies!

So a little more on this.

I am running a loop inside the ServerScriptService.

Stepping through the debugger using the suggested snippet of:

player.Character.FindFirstChildOfClass("Fire")

returns *** Value Not Found *** in the Watch View throughout the loop below.

Does findFirstChild iterate through Children of Children?




1 #-######a####o####
2 while true do
3
4 --check players
5 for i, player in ipairs(game.Players:GetPlayers()) do
6
7
8 if(player.Character:findFirstChildOfClass("Fire")) then
9 local hum = player.Character:FindFirstChild('Humanoid')
10 hum.Health = hum.Health - 1
11 end
12 end
13 end




I did find an error in the code I previously posted. Here is the corrected code that is working. If anyone has a more efficient way to do it though, I would still be interested.


function CheckPlayers()

for i, player in ipairs(game.Players:GetPlayers()) do

local fire = false
if player.Character then
local localPlayer =
game.Players:GetPlayerFromCharacter(player.Character)
local hum = player.Character:FindFirstChild('Humanoid')

if(player.Character["LeftLowerArm"]) then
local limb = player.Character["LeftLowerArm"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end
if(player.Character["LeftUpperArm"]) then
local limb = player.Character["LeftUpperArm"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end
if(player.Character["RightLowerArm"]) then
local limb = player.Character["RightLowerArm"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end
if(player.Character["RightUpperArm"]) then
local limb = player.Character["RightUpperArm"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end
if(player.Character["Pants"]) then
local limb = player.Character["Pants"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end
if(player.Character["LeftLowerLeg"]) then
local limb = player.Character["LeftLowerLeg"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end
if(player.Character["LeftUpperLeg"]) then
local limb = player.Character["LeftUpperLeg"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end
if(player.Character["RightLowerLeg"]) then
local limb = player.Character["RightLowerLeg"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end
if(player.Character["RightUpperLeg"]) then
local limb = player.Character["RightUpperLeg"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end
if################################hen
local limb = pl############################ if(limb:FindFirstChild("Fire")) then
fire = true
end
end
if(player.Character["RightFoot"]) then
local limb = player.Character["RightFoot"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
if(player.Character["LeftHand"]) then
local limb = player.Character["LeftHand"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end
if(player.Character["RightHand"]) then
local limb = player.Character["RightHand"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end
if(player.Character["LowerTorso"]) then
local limb = player.Character["LowerTorso"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end
if(player.Character["UpperTorso"]) then
local limb = player.Character["UpperTorso"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end
if(player.Character["Head"]) then
local limb = player.Character["Head"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end
if(player.Character["Shirt"]) then
local limb = player.Character["Shirt"]
if(limb:FindFirstChild("Fire")) then
fire = true
end
end


if(fire)then
hum.Health = hum.Health - 1
end
end
end
end
end

--main game loop in ServerScriptService
while true do

CheckPlayers()

end
Report Abuse
broadbandrob is not online. broadbandrob
Joined: 09 May 2017
Total Posts: 9
31 May 2017 09:18 PM
Here is the snipped from where it somehow changed to ####### after I posted. ################################ then local limb = ############################ if(limb:FindFirstChild("Fire")) then fire = true end end
Report Abuse
broadbandrob is not online. broadbandrob
Joined: 09 May 2017
Total Posts: 9
31 May 2017 09:20 PM
Apparently copy and paste isn't working for that portion. I'll try typing it. ################################ then local limb = ############################ if(limb:FindFirstChild("Fire")) then fire = true end end
Report Abuse
Cuyler is not online. Cuyler
Joined: 27 Feb 2006
Total Posts: 3784
31 May 2017 09:22 PM
for _, Player in ipairs(game:GetService("Players"):GetPlayers()) do
if (Player.Character and Player.Character:FindFirstChildOfClass("Humanoid") and Player.Character:FindFirstChild("Fire", true)) then
Player.Character:FindFirstChildOfClass("Humanoid"):TakeDamage(1);
end
end


Report Abuse
FumeiSencho is not online. FumeiSencho
Joined: 07 Apr 2013
Total Posts: 452
31 May 2017 09:24 PM
put ^^ in a while ####### ####
Report Abuse
EnviedWolf is online. EnviedWolf
Joined: 08 Apr 2010
Total Posts: 690
31 May 2017 09:40 PM
for u,v in pairs(game.Playes:GetChildren()) do
for z,c in pairs(v:GetChildren()) do
if c:FindFirstChild("Fire") then
For 1 = 1,10 do
Humanoid:TakeDamage(2)
wait(2)
end
end
end
end
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
31 May 2017 10:54 PM
Here.


local Players = game:GetService("Players")

local function CheckPlayers()
for _, player in ipairs(Players:GetPlayers()) do
local Character = player.Character

if Character then -- has not spawned yet?
local Humanoid = Character:FindFirstChildOfClass("Humanoid")

if Humanoid then -- stuff?
if Character:FindFirstChild("Fire", true) then -- true for recursive
Humanoid:TakeDamage(1)
end
end
end
end
end

while true do
CheckPlayers()
wait()
end


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