Hello! I've been trying to create a script that sets the player on fire, and causes them to take damage over time. While the effect of the fire is there, the player doesn't take any damage for some reason. This is the script
local firePart = script.Parent
firePart.Transparency = 1
local function LightOnFire(part)
local fire = part:FindFirstChild("Fire")
if not fire then
fire= Instance.new("Fire")
fire.Parent = part
while true do
game.Players.LocalPlayer.Character.Humanoid.Health =game.Players.LocalPlayer.Character.Humanoid.Health - 15
wait(5)
end
end
end
firePart.Touched:connect(LightOnFire)
-- what I want to do is add in a part to the script where if the player
--steps on the fire, they take damage
You are using Players.LocalPlayer
in the server side. This is going to be nil
. The server is not a player, and has no player of its own either.
You can get the player from their character via the Players:GetPlayerFromCharacter
method.
```lua local firePart = script.Parent; local Players = game:GetService("Players");
firePart.Touched:Connect(function(part) local client = Players:GetPlayerFromCharacter(part.Parent);
if (client) then --// Light them on fire! client is now the player. You can access their character using client.Character end
end); ```