Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

<Answered> Can anyone explain to me why my fire script doesn't apply damage to the player?

Asked by 5 years ago
Edited 5 years ago

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

1 answer

Log in to vote
0
Answered by 5 years ago

LocalPlayer is nil to the server

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); ```

0
ahh This looks nice, but is the semi colon at the end of each line required? I haven't seen anyone use them before. dragonspade21 15 — 5y
0
And as for the function(part). Could I insert my own function to replace part? dragonspade21 15 — 5y
0
and lastly, how would I get the player to take damage in this sense? Like how would I be able to access their health? dragonspade21 15 — 5y
Ad

Answer this question