I been using this script for months and never touched it and now it just now gives me errors and this is off a book I bought and learned LUA off of.
script.Parent.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
Humanoid:TakeDamage(7)
end
end)
1 Like
Most LUA books are for the base language of Lua. For help on rbx.lua, use the Roblox Developer Hub. Can you attach the error message you’re receiving?
2 Likes
No, my book title is called LUA Learning for Roblox Beginners and Intermediate.
1 Like
script.Parent.Touched:Connect(function(hit)
if hit.Parent then
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
Humanoid:TakeDamage(7)
end
end
end)
2 Likes
It also appears you only end your if statement and not the entire function. @DybalaplaysYT reply also fixes this, but I’d just like to point that out.
2 Likes
Thanks so much both of you guys! It appeared I needed the if hit then.
2 Likes
You should also consult the Roblox Developer Hub, as it contains the most up-to-date information; books can’t do that.
Glad to know we could help! Happy deving!
2 Likes