✓ Accepted answer
You can pass variable from one to another function.
Example:
function one()
local number = 10 + 1
print(two(number))
end
function two(number)
return number + 1
end
So in your script you can do the same!
local object = script.Parent
local firePlayer = game.ReplicatedStorage.Fire
function fireTheGui(hit)
local playersHead = hit.Parent.Head
local player = hit.Parent.HumanoidRootPart
local playersHealth = hit.Parent.Humanoid
if player then
firePlayer.Parent = playersHead
playerDamage(playersHead, playersHealth)
end
end
object.Touched:Connect(fireTheGui)
function playerDamage(playersHead, playersHealth)
if playersHead.Fire then
playersHealth:TakeDamage(2)
print("This player is taking Damage")
end
end
Also there's another way doing this with local function:
With my understanding local function allows another function to read all non-local variables inside it.
function two()
return num
end
local function one()
num = 100
print(two())
end
one()
So in your script:
local object = script.Parent
local firePlayer = game.ReplicatedStorage.Fire
local function fireTheGui(hit)
playersHead = hit.Parent.Head
local player = hit.Parent.HumanoidRootPart
playersHealth = hit.Parent.Humanoid
if player then
firePlayer.Parent = playersHead
playerDamage()
end
end
object.Touched:Connect(fireTheGui)
function playerDamage()
if playersHead.Fire then
playersHealth:TakeDamage(2)
print("This player is taking Damage")
end
end
ALSO if you want to make the player takes damage while the fire is still on their head then do this:
function playerDamage()
if playersHead.Fire then
while wait() do
playersHealth:TakeDamage(2)
if playersHead:FindFIrstChild("Fire") == false then
break
end
end
end
end
function playerDamage()
if playersHead.Fire then
repeat wait()
playersHealth:TakeDamage(2)
until playersHead:FindFirstChild("Fire") == false
end
end
4 comments
But I would like the player to take damage while not touching the block
I should've mentioned that
I edited it!
Nailed it man. Mind if I send you a friends req on roblox?