--Interact Script

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local cam = game.Workspace.CurrentCamera
local deb = false
local door = game.Workspace.Door.Model.door



while true do wait()
	if mouse.Target:FindFirstChild("canInteract") then
		if deb == false then deb = true
			script.Parent.Background.Visible = true
			mouse.KeyDown:connect(function(Key)
				if Key == "e" then 
				if mouse.Target.canInteract.Value == "door" then
				door.Script.Disabled = false
				wait(4)
				door.Script.Disabled = true
				end
				end	
			end)
			wait()
			deb = false
		end
	else
		if deb == false then deb = true
			script.Parent.Background.Visible = false
			wait()
			deb = false
		end
	end
end

Error:Players.Player.PlayerGui.Interact.interactScript:12: attempt to index field 'Target' (a nil value)

Help anyone? This is a door interaction script. Everything works but it keeps saying the target is a nil value. Target is the door

5 comments

0

You need to check to see if the door exists. Mouse.Target is nil by default, so it is only an object when on something.

0

Could you write me an example?

0

if Mouse.Target then ... end;

0

Are you actually clicking on something. If not then by default mouse.Target will always be equal to nil. You also need to make sure your clicking on the actual object.

0

Okay so if the mouse hovers over the door the GUI will become visible and it will say "Press E to Interact" and then once the mouse stops hovering over the door it will go away. Also it has to recognize it as a door, so I put a string value having the value "Door" so once the mouse hovers over the door it makes sure the value is door so it does a certain action to open the door