So, I'm working on a game where you can turn into a prop as soon as you click a part in workspace. The problem is that it does work until you become the prop, after that you can't click the parts again and you get errors if you click somewhere (even if you click the sky). Can anyone help me with this?
Localscript:
local events = game.ReplicatedStorage.Events
local colorevent = events.ChangeColor
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local gui = Player.PlayerGui
local mouseM = gui.HUD.MouseMessage
local props = game.ReplicatedStorage.Props
colorevent.OnClientEvent:connect(function(Color)
end)
Mouse.Move:connect(function()
local X, Y = Mouse.X, Mouse.Y
if Mouse.Target ~= nil then
local a = Mouse.Target.Position
if Mouse.Target.Parent:FindFirstChild("IsProp") and
X > gui.HUD.AbsolutePosition.x and
X > gui.HUD.AbsolutePosition.x and
X < gui.HUD.AbsolutePosition.x+gui.HUD.AbsoluteSize.x and
Y < gui.HUD.AbsolutePosition.y+gui.HUD.AbsoluteSize.y
then
if Player:DistanceFromCharacter(a) < 18 then
mouseM.Visible = true;
mouseM.Position = UDim2.new(0,X+1,0,Y+1);
mouseM.Text = "Turn into a "..Mouse.Target.Parent.IsProp.Propname.Value;
Mouse.Button1Down:connect(function()
local b = Mouse.Target.Parent.IsProp.Propname.Value
events.SpawnCharacters:FireServer("unfinished",b)
end)
else
mouseM.Visible = false;
mouseM.Text = ""
end
else
mouseM.Visible = false;
mouseM.Text = ""
end
end
end)
This is the error:
16:29:20.864 - Players.Player1.PlayerScripts.Framework:28: attempt to index field 'Target' (a nil value)
16:29:20.865 - Stack Begin
16:29:20.866 - Script 'Players.Player1.PlayerScripts.Framework', Line 28
16:29:20.867 - Stack End
