Hello! This is my first post ever on this website, but I have a problem to solve and I need help from someone. I have a FireScript (Normal Script) but when I want to remove the fire from my HumanoidRootPart, it does not work. The line that should be responsible for that is Line 23. I've sent some info.
-- Variables local firePart = script.Parent local Players = game.Players -- Scripting In Action function LightOnFire(hit) local fire = hit.Parent:FindFirstChild("Fire") if fire then else local FireInstance = Instance.new("Fire") FireInstance.Name = "HumanoidFire" FireInstance.Heat = 13 FireInstance.Size = 9 if hit.Parent:FindFirstChild("Humanoid") then FireInstance.Parent = hit.Parent.HumanoidRootPart local Humanoid = hit.Parent:FindFirstChild("Humanoid") wait(2.5) Humanoid.Health = Humanoid.Health -10 wait(3) local PlayerOnFire = > game.Workspace[Player].HumanoidRootPart:FindFirstChild("HumanoidFire") if PlayerOnFire then PlayerOnFire:Destroy() end end end end firePart.Touched:Connect(LightOnFire)
I will be waiting for some answers, I can send more info if you would like.
Hey there! I went ahead and rewrote some parts of your script for you and it should now work.
I have spotted some issues in your code that I don't know if was intentional because of some other pieces of code you may have hidden but I have spotted some.
Lemme give you a rundown of what I've spotted and what you should also do to make this code run better as I have spotted a few issues with it.
If you don't know.. the -- are comments. Read these comments for info on why your code didn't work and also just for a better understanding of the code :)
local firePart = script.Parent local Players = game:GetService("Players") -- Personally, I would use GetService to get the service Players instead of game.Players as it's much safer to use than game.Players. If you would like to know the benefits of GetService I would go to this link: https://devforum.roblox.com/t/is-there-an-advantage-to-using-getservice/1297895 function LightOnFire(hit) local fire = hit.Parent:FindFirstChild("Fire") if not fire then -- I don't know if you hid code in your first block for your Else statement but if you want to use the Else block only and not the first block, you use "not" as it changes the condition to the opposite. local FireInstance = Instance.new("Fire") FireInstance.Name = "HumanoidFire" FireInstance.Heat = 13 FireInstance.Size = 9 if hit.Parent:FindFirstChild("Humanoid") then FireInstance.Parent = hit.Parent.HumanoidRootPart local Humanoid = hit.Parent:FindFirstChild("Humanoid") wait(2.5) Humanoid.Health -= 10 -- If you're using any sort of operation with the same number, you don't need to type the numbertwice. Instead you can do this, this works with all operations from what I know. EX: +=, -=, /=, *= wait(3) local PlayerOnFire = hit.Parent.HumanoidRootPart:FindFirstChild("HumanoidFire") -- I have a lot to say about this line. 1, instead of typing "game.Workspace" you can type just "workspace". 2. You had a ">" at the beginning of the variable for some reason. 3. You are trying to find a child with a non-existant variable in workspace? You might've just hid some code for this variable but for square brackets, you usually use these for things with spaces or existing variables that you don't know the name of when ran ingame. Now you did choose the second part that I said for the square bracket BUT once again, that variable was non-existant from the code you gave us. if PlayerOnFire then PlayerOnFire:Destroy() end end end end firePart.Touched:Connect(LightOnFire)
Now here is what I recommend, this rewritten code is good and all but has ONE major flaw to it. It doesn't have a DEBOUNCE, a player can touch the part and the function that sets them on fire will run MULTIPLE times. I tried it out and my health was reduced BY 90 because it ran 9 times. This is all when I STEPPED on it ONCE.
Make sure to add a debounce to your script! If you want the debounce to only be specific to players, you'll need a local script, remote event and script.
BTW when I say debounce I mean as in a cooldown.
Good luck with scripting, it truly is amazing.
Thank you so much for helping! The script actually worked but I edited a few parts, how do I mark your answer?
Edit: Nvm I figured out how to mark answers correct.