I made a fire script that damges the player when they step on a burning part. The fire script works, but it only affects one player at a time. I have no idea how to make it apply to multiple players.
Here is the code
The first script, detects if the player is touching the part and checks of the player isn't already burning
[REGULAR SCRIPT]
script.Parent.Parent.Touched:Connect(function(SpreadPart)
if SpreadPart:FindFirstChild("FireScript") == nil and SpreadPart.Locked == false then
if game.Players:FindFirstChild(SpreadPart.Parent.Name) then
if SpreadPart.Parent:FindFirstChild("Humanoid") then
if game.Players:FindFirstChild(SpreadPart.Parent.Name) then
local player = game.Players:FindFirstChild(SpreadPart.Parent.Name)
if player.isBurning.Value == false then
if script.Parent.Parent:FindFirstChild("Fire") then
player.isBurning.Value = true
game.Workspace.DamageSend:FireClient(player)
end
end
end
end
else
script.Parent.Parent.FireScript:Clone().Parent = SpreadPart
end
end
end)
Then it fires the client to prepare for damge
[LOCAL SCRIPT]
local isBurning = game.Players.LocalPlayer:WaitForChild("isBurning")
game.Workspace.DamageSend.OnClientEvent:Connect(function()
if isBurning.Value == true then
game.Workspace.DamagePlayer:FireServer()
end
end)
Then the local script fires another event to damage the player
[REGULAR SCRIPT]
script.Parent.OnServerEvent:Connect(function(client)
print("Damaged:"..client.Name)
local player = game.Players:FindFirstChild(tostring(client))
local isBurning = player:FindFirstChild("isBurning")
local Sound = game.ReplicatedStorage.Fire.Sound
local Embers = game.ReplicatedStorage.Fire.Embers
local Fire = game.ReplicatedStorage.Fire.Fire
local Light = game.ReplicatedStorage.Fire.PointLight
local player = game.Workspace:FindFirstChild(client.Name)
local count = 0
if player.UpperTorso:FindFirstChild("PointLight") then
else
Sound:Clone().Parent = player.UpperTorso
Embers:Clone().Parent = player.LowerTorso
Embers:Clone().Parent = player.UpperTorso
Fire:Clone().Parent = player.LowerTorso
Fire:Clone().Parent = player.UpperTorso
Light:Clone().Parent = player.LowerTorso
player.UpperTorso.Sound:Play()
repeat
if isBurning.Value == true then
wait(0.5)
player.Humanoid.Health = player.Humanoid.Health - 5
count = count + 1
else
break
end
until count == 6
player.UpperTorso.Sound:Stop()
player.LowerTorso.Embers.Enabled = false
player.UpperTorso.Embers.Enabled = false
player.LowerTorso.Fire.Enabled = false
player.UpperTorso.Fire.Enabled = false
player.LowerTorso.PointLight:Destroy()
isBurning.Value = false
wait(1)
player.LowerTorso.Embers:Destroy()
player.UpperTorso.Embers:Destroy()
player.LowerTorso.Fire:Destroy()
player.UpperTorso.Fire:Destroy()
end
end)
Any help is appreciated!
