Lava Touched Animation and Function Not Working

Hello! Im trying to make a SM64 styled game and when the player touches the lava for some reason the animation doesnt load and the health isnt taken away by 3

Script

local humanoid = game.Player.Humanoid
local Players = game:GetService("Players")
local lavaHitAnimation = "rbxassetid://6872512512"

if humanoid.Touched == script.Parent then
	humanoid.Health = humanoid.Health - 3
	
	lavaHitAnimation:Play()
end

What came in the output

 12:36:17.448  Super Oofy 64 @ 27 May 2021 12:36 auto-recovery file was created  -  Studio - C:/Users/mrtix/OneDrive/Documents/ROBLOX/AutoSaves
  12:36:20.146  Player is not a valid member of DataModel "Super Oofy 64 @ 27 May 2021 12:36"  -  Server - Lava.TouchedController:1
  12:36:20.147  Stack Begin  -  Studio
  12:36:20.147  Script 'Workspace.Volcano.Lava.Lava.TouchedController', Line 1  -  Studio - Lava.TouchedController:1
  12:36:20.147  Stack End  -  Studio
  12:36:35.740  Workspace.NubblyFry.DeathAnimation:2: Expected identifier when parsing variable name, got <eof>  -  Studio - DeathAnimation:2
  12:36:36.503  Workspace.FallDamageScript:17: attempt to perform arithmetic (sub) on nil and number  -  Server - FallDamageScript:17
  12:36:36.504  Stack Begin  -  Studio
  12:36:36.504  Script 'Workspace.FallDamageScript', Line 17  -  Studio - FallDamageScript:17
  12:36:36.504  Stack End  -  Studio
  12:36:38.512  0.5, 0.5  -  Server
  12:36:38.749  0.5, 0.5  -  Client
  12:37:38.608  Disconnect from ::ffff:127.0.0.1|58400  -  Studio
  12:38:41.485   â–¶ Super Oofy 64 auto-recovery file was created (x3)  -  Studio - C:/Users/mrtix/OneDrive/Documents/ROBLOX/AutoSaves
1 Like

try this instead:

humanoid.Touched:Connect(function(hit)
	if hit.Name == script.Parent.Name then
      humanoid.Health -= 3
	
	lavaHitAnimation:Play()
   end
end)
2 Likes

this came in the output

  12:54:10.082  Player is not a valid member of DataModel "Super Oofy 64 @ 27 May 2021 12:54"  -  Server - Lava.TouchedController:1
  12:54:10.083  Stack Begin  -  Studio
  12:54:10.083  Script 'Workspace.Volcano.Lava.Lava.TouchedController', Line 1  -  Studio - Lava.TouchedController:1
  12:54:10.083  Stack End  -  Studio
  12:54:26.254  Workspace.NubblyFry.DeathAnimation:2: Expected identifier when parsing variable name, got <eof>  -  Studio - DeathAnimation:2
  12:54:27.371  Workspace.FallDamageScript:17: attempt to perform arithmetic (sub) on nil and number  -  Server - FallDamageScript:17
  12:54:27.371  Stack Begin  -  Studio
  12:54:27.371  Script 'Workspace.FallDamageScript', Line 17  -  Studio - FallDamageScript:17
  12:54:27.371  Stack End  -  Studio
  12:54:29.123  0.5, 0.5  -  Server
  12:54:29.364  0.5, 0.5  -  Client
1 Like

lavaHitAnimation:Play() wouldn’t work, as you’re firing a function at a string. Instead, utilise Animator:LoadAnimation() to create an animation track for your humanoid, then :Play() it.

local humanoid = game.Player.Humanoid --you're specifying "Humanoid" as a player

change it to (completely):

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local lavaHitAnimation = "rbxassetid://6872512512"

instead of using

humanoid.Health -= 3

use

Humanoid:TakeDamage(3)
2 Likes
  13:08:51.661  Player is not a valid member of DataModel "Super Oofy 64 @ 27 May 2021 13:08"  -  Server - Lava.TouchedController:2
  13:08:51.662  Stack Begin  -  Studio
  13:08:51.662  Script 'Workspace.Volcano.Lava.Lava.TouchedController', Line 2  -  Studio - Lava.TouchedController:2
  13:08:51.662  Stack End  -  Studio
  13:09:04.031  Workspace.NubblyFry.DeathAnimation:2: Expected identifier when parsing variable name, got <eof>  -  Studio - DeathAnimation:2
  13:09:13.864  Workspace.FallDamageScript:17: attempt to perform arithmetic (sub) on nil and number  -  Server - FallDamageScript:17
  13:09:13.866  Stack Begin  -  Studio
  13:09:13.866  Script 'Workspace.FallDamageScript', Line 17  -  Studio - FallDamageScript:17
  13:09:13.866  Stack End  -  Studio
  13:09:16.609  0.5, 0.5  -  Server
  13:09:17.145  0.5, 0.5  -  Client
  13:11:50.605  Workspace.NubblyFry.DeathAnimation:2: Expected identifier when parsing variable name, got <eof>  -  Studio - DeathAnimation:2

Seems like you’re doing it in a script instead.

use game.Players.PlayerAdded instead.

local lavaHitAnimation = "rbxassetid://6872512512"
game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        local hum = char:WaitForChild("Humanoid")
        --code here
    end)
end)
1 Like

Also I was trying to make it so if the player touched the lava ( script.Parent ) then it would happen

So like this?

local plr = game.Players.PlayerAdded
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local lavaHitAnimation = "rbxassetid://6872512512"

hum.Touched:Connect(function(hit)
	if hit.Name == script.Parent.Name then
		hum:TakeDamage(3)

		lavaHitAnimation:Play()
	end
end)

Include this in your code for it to play the animation.

1 Like
local plr = game.Players.PlayerAdded
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local lavaHitAnimation = "rbxassetid://6872512512"

hum.Touched:Connect(function(hit)
	if hit.Name == script.Parent.Name then
		hum:TakeDamage(3)
		
		hum:LoadAnimation(lavaHitAnimation)
		lavaHitAnimation:Play()
	end
end)

You’ll need to connect a Touched event to the part.
Right now your attempting to check if Humanoid.Touched is equal to the scripts parent, this wouldn’t work and would probably return false.

Also instead of putting the id create a new Animation Instance, set the AnimationId, and use LoadAnimation.

local Players = game:GetService("Players")
local lavaHitAnimation = Instance.new("Animation")
lavaHitAnimation.AnimationId = "rbxassetid://6872512512"

script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    local player = Players:GetPlayerFromCharacter(hit.Parent)
    if not player or not humanoid then return end

    local lavaHitTrack = humanoid.Animator:LoadAnimation(lavaHitAnimation)

	humanoid:TakeDamage(3)
	lavaHitTrack:Play()
end)

(Sorry if my explaining is bad lol)

1 Like
 13:29:09.607  Super Oofy 64 @ 27 May 2021 13:29 auto-recovery file was created  -  Studio - C:/Users/mrtix/OneDrive/Documents/ROBLOX/AutoSaves
  13:30:01.140  Workspace.NubblyFry.DeathAnimation:2: Expected identifier when parsing variable name, got <eof>  -  Studio - DeathAnimation:2
  13:30:04.198  Workspace.FallDamageScript:17: attempt to perform arithmetic (sub) on nil and number  -  Server - FallDamageScript:17
  13:30:04.227  Stack Begin  -  Studio
  13:30:04.228  Script 'Workspace.FallDamageScript', Line 17  -  Studio - FallDamageScript:17
  13:30:04.228  Stack End  -  Studio
  13:30:12.397  0.5, 0.5  -  Server
  13:30:13.645  0.5, 0.5  -  Client

Place the Script in the Instance.

Fixed the code, also make sure the put the code I sent inside the death part.

1 Like

It works, but why does this happen?

  13:52:21.134  Workspace.NubblyFry.DeathAnimation:2: Expected identifier when parsing variable name, got <eof>  -  Studio - DeathAnimation:2