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)
First of all, you need to tab your code.
Using script.Parent.Parent.Parent.Name
repeatedly the way you are is not advisable.
If this is a LocalScript, you can refer directly to the current player by game.Players.LocalPlayer
. Otherwise, let's simplify your references with just a few sweet lines:
player = game.Players[ script.Parent.Parent.Parent.Name ] repeat character = player.Character wait() until character
You should definitely not be doing Worksapace[hit.Name]
. Just use hit
.
Doing things like
elseif hi.placer then -- also a typo...
Dont' work. If placer
isn't a child of hi
, then you just error.
Use :FindFirstChild
.
I'm not sure what you mean by hit.Name:gsub(hit.Name:sub(1,4),"")
If you want from position five onward, just use hit.Name:sub(5)
.
You should really work slower and think more carefully, and probably review the simpler stuff.