Yep, title. That is the error, I really don't get it. The script worked before I added the "lucky block" portion. (All but the Lucky Block portion works, it is sectioned out.)
Thanks for all the help.
function onButton1Down(mouse)
print(game.Workspace[script.Parent.Parent.Parent.Name])
posp = game.Workspace[script.Parent.Parent.Parent.Name].Head.Position
local ray = Ray.new(game.Workspace[script.Parent.Parent.Parent.Name].Head.Position, mouse.Hit.p)
local hit, position = game.Workspace:FindPartOnRay(ray, game.Workspace[script.Parent.Parent.Parent.Name])
--do damage to any humanoids hit
local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")
--draw the ray
local distance = (position - posp).magnitude
local rayPart = Instance.new("Part", game.Workspace)
rayPart.Name = "RayPart"
rayPart.BrickColor = BrickColor.new("Bright red")
rayPart.Transparency = 0.5
rayPart.Anchored = true
rayPart.CanCollide = false
rayPart.TopSurface = Enum.SurfaceType.Smooth
rayPart.BottomSurface = Enum.SurfaceType.Smooth
rayPart.formFactor = Enum.FormFactor.Custom
rayPart.Size = Vector3.new(0.2, 0.2, distance)
rayPart.CFrame = CFrame.new(position, posp) * CFrame.new(0, 0, -distance/2)
game.Debris:AddItem(rayPart, 0.1)
if hit == nil then
elseif game.Workspace[hit.Name].type ~= nil and hit.Name:gsub(hit.Name:sub(1,4),"") == "Turbo" then
print("plane hit")
game.Workspace.explode:play()
-- game.Workspace[hit.Name].Position = Vector3.new(-68, 12, -43.5)
game.Workspace[hit.Name]:remove()
-- print(game.Workspace[hit.Name].Position)
local h = Instance.new("Hint", game.Players[script.Parent.Parent.Parent.Name].PlayerGui)
text = " "..hit.Name:gsub(hit.Name:sub(1,4), "").." destroyed."
for i = 1, #text do
h.Text = text:sub(i)
wait(.1)
end
h:remove()
-- NEW AREA THAT ERRORS BELOW
elseif game.Workspace[hit.Name].placer then
local h = Instance.new("Hint", game.Players[script.Parent.Parent.Parent.Name].PlayerGui)
text = " Lucky Block Opened."
for i = 1, #text do
h.Text = text:sub(i)
wait(.1)
end
h:remove()
end
end
-- END FAIL AREA
function onSelected(mouse)
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end
script.Parent.Selected:connect(onSelected)
