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
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
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"
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
local lavaHitAnimation = "rbxassetid://6872512512"
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
--code here
end)
end)
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)
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)
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