✓ Accepted answer
You don't need a bracket to close the local function, as you aren't using ":connect".
In addition, you didn't define the variable "Part", which should be defined as the function's first argument (ROBLOX always gives this argument when handling Touched events!)
I've corrected it for you here.
local lava = script.Parent
lava.Touched:connect(function(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid then
local char = part.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
if plr then
plr.Character:BreakJoints()
end
end
end)
If this helped, please press "Accept Answer", as it helps others like you find what they're looking for! :)
--
This is what I changed:
Instead of defining a function first, then connecting to it, I just connected to a newly defined function. Example:
function PrintHelloWorld()
print("Hello world!")
end
script.Parent.Touched:connect(HelloWorld)
script.Parent.Touched:connect(function()
print("Hello world!")
end)
Next, instead of changing the Humanoid's health to zero, I found the character and broke joints.
local char = part.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
if plr then
plr.Character:BreakJoints()
end
Have a nice day! :D
NEW SCRIPT:
lava.Touched:connect(function(victim)
local humanoid = victim.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end)
8 comments
That's nothing like my original script. I want to try to learn Lua but I can't if you corrected my script with a completely different script that I do not even understand.
Sorry, but it's doing the same thing in a different way. I'll edit it quickly to explain what I changed.
There, I've edited it! Feel free to read, and I hope you'll learn a thing or two! :D
I tried changing my script to work my own way but it did not work. Can you explain to me what I did wrong but can you fix it in my version of the script instead of your version? I will edit the new script onto my question.
Alright, I'll try.
Right, I've added it to the end :)
Thanks!
You're welcome :)