To begin, I've got a script that will detect if hit
or hit.Parent
is Nil
when a block is touched. It reads off whether hit
or hit.Parent
is nil
in the output at the start of the script, and is supposed to cancel going any farther if either is Nil
since it will cause errors later on. However, it isn't working correctly, and will tell me something isn't Nil
, then give me an error when I touch the block with it (stating that it's canceling because of a Nil
value)
This is NOT a LocalScript
. Here's the script thus far:
local debounce = false local splinter = game.Lighting.Splinters script.Parent.door.check.Touched:connect(function(hit) print("It is "..(tostring(hit == nil)).." that "..(tostring(hit)).." is nil!") print("It is "..(tostring(hit.Parent == nil)).." that "..(tostring(hit)).."'s parent is nil!") if (hit.Parent == nil) or (hit == nil) then print("Oooh, big scery ghoost.") return else if debounce == false then local walkspede = game.Players:GetPlayerFromCharacter(hit.Parent).Character.Humanoid.WalkSpeed if walkspede == 24 then debounce = true script.Parent.DoorKnob1.Anchored = false script.Parent.door:Destroy() for i = 1, 16 do splinter.Splinter1:Clone().Parent = script.Parent.burstpoint print("Clone1") -- I should probably remove these... oh well. splinter.Splinter2:Clone().Parent = script.Parent.burstpoint print("Clone2") splinter.Splinter3:Clone().Parent = script.Parent.burstpoint print("Clone3") splinter.Splinter4:Clone().Parent = script.Parent.burstpoint print("Clone4") end game.Players:GetPlayerFromCharacter(hit.Parent).Character.Humanoid.PlatformStand = true wait(1) game.Players:GetPlayerFromCharacter(hit.Parent).Character.Humanoid.PlatformStand = false wait(1) debounce = false else debounce = true print ((tostring(hit.Parent))..", walk fastr scrub!1!!1") -- Prints like this are what keep me entertained whilst coding... wait(1) debounce = false end end end end)
Whenever I touch the block mentioned above with another block called "DoorKnob1", it gives me these lines in the output:
If somebody could explain to me why it's contradicting itself (at least, seems to be) and how to resolve the error, I'd be very grateful.
Thank you for reading, and hopefully you won't be as confused as I am!