Ok so I been modifying this Door System that let's users click the door and teleport to the other door in the same model but when I click the door it comes up with this error attempt to index field 'Target' (a nil value) How can I get it to be fixed?
Here's the section the error appears on.
-- Main Values
local Mouse = game.Players.LocalPlayer:GetMouse()
local player = game.Players.LocalPlayer
-- Check whether the mouse has been moved and check whether a description needs to be shown.
Mouse.Move:connect(function()
local target = Mouse.Target
if target then
if not player.Character or not player.Character:FindFirstChild("Torso") then
return
end
local distance = (player.Character.Torso.Position - target.Position).magnitude
local message -- What to say
if target.Parent:FindFirstChild('Head') and target.Parent:FindFirstChild('Torso') and distance < 25 then
message = target.Parent.Name;
elseif target.Parent:FindFirstChild('Item') and distance < 15 then
message = target.Parent.Item.Value;
end
if message then
if not player.PlayerGui:FindFirstChild("Description") then
local description = game.ReplicatedStorage["Door System"].Graphics.Description:Clone()
description.Parent = player.PlayerGui
end
local description = game.ReplicatedStorage["Door System"].Graphics.Description:Clone()
description.Information.Text = message
else
if player.PlayerGui:FindFirstChild("Description") then
player.PlayerGui.Description:Destroy()
end
end
end
end)
-- Check whether the player has decided to click something I.E a door or a torch.
Mouse.Button1Down:connect(function()
local Target = Mouse.Target
if Target then
if Target.Parent.Name == 'FirstDoor' then
repeat wait() until game.Players.LocalPlayer.Character
local Magnitude = (game.Players.LocalPlayer.Character.Torso.Position - Target.Position).magnitude
if Magnitude < 10 then
game.ReplicatedStorage['Door System'].Events.WalkThroughDoor:FireServer(Target.Parent, Target.Parent.Parent:FindFirstChild('SecondDoor'))
end
elseif Target.Parent.Name == 'SecondDoor' then
repeat wait() until game.Players.LocalPlayer.Character
local Magnitude = (game.Players.LocalPlayer.Character.Torso.Position - Target.Position).magnitude
if Magnitude < 10 then
game.ReplicatedStorage['Door System'].Events.WalkThroughDoor:FireServer(Target.Parent, Target.Parent.Parent:FindFirstChild('FirstDoor'))
end
end
end
end)

2 comments
Thx for fixing it but now the next part of the script does not work at all... I edited my post with the full code this time.
it also shows label not the name of the part it's on.