Hi. I've created a random map script which loads a random map every so often. I decided to make it so that instead of putting a script inside each lava part, to instead make a script which automatically changes them into 'lava' bricks.
However, it doesn't seem to work. How do I fix this?
The output doesn't say anything.
Workspace.ProgramHolder.Changed:connect(function() p = Workspace.ProgramHolder if p:GetChildren()[1] ~= nil then c = p:GetChildren() for i, v in next, c:GetChildren() do if v.Name == "lava" and v:IsA("Part") then v.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Torso", true) then hit.Parent.Torso.CFrame = CFrame.new(73, 148.8, -181.2) -Vector3.new(math.random(-5,5),math.random(0,0),math.random(-5, 5)) end end) end end end end)
Thank you.
Here is a lava script for when a person steps on it, the person dies (IF THIS IS WHAT YOU WANT)
function onTouch(part) local humanoid = part.Parent:FindFirstChild("Humanoid") if (humanoid ~= nil) then -- if a humanoid exists, then humanoid.Health = 0 -- damage the humanoid end end
script.Parent.Touched:connect(onTouch)
It's very simple. I did it like this: (There's a brick with a script inside)
script.Parent.Touched:connect(function(touched) local found = touched.Parent:FindFirstChild("Humanoid") if found then touched.Parent.Humanoid.Health = 0 end end)
Hope this helps.