|
local part = game.ReplicatedStorage.TheBrick:Clone()
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Move:connect(function()
if mouse.Target then
if mouse.Target.Name == "HOVER_TRUE" then
part.Parent = game.Workspace
part.Position = mouse.Hit.p
part.Transparency = 0.5
else
if mouse.Target.Name ~= part.Name then
part:remove()
end
end
end
end)
This error will occasionally pop up:
attempt to index field 'Target' (a nil value)
is their a way to prevent this?
|
|
|
70o11Join Date: 2013-07-18 Post Count: 18 |
Try this:
local part = game:GetService("ReplicatedStorage"):FindFirstChild("TheBrick"):Clone()
local player = game:GetService("Players")
local mouse = player:GetMouse()
local pos = mouse.Hit.p
mouse.Move:connect(function()
if mouse.Target then
if mouse.Target.Name == "HOVER_TRUE" then
part.Parent = game:GetService("Workspace")
part.Position = pos
part.Transparency = 0.5
else
if mouse.Target.Name ~= part.Name and "HOVER_TRUE" then
part:remove()
end
end
end)
Either the above should work or Target is not a property and Target is not a variable.
|
|
|
GetMouse is not a valid member of Players |
|
|
Oh.. I fixed it..
This error still occurs though:
Players.Player1.Backpack.LocalScript:12: attempt to index field 'Target' (a nil value)
It is not a constant error, the script still works its just I'd rather not have an error being broadcasted randomly |
|
|
eleyeJoin Date: 2010-10-31 Post Count: 599 |
"(a nil value)"
you haven't given "Target" a variable
|
|
Hedr0nJoin Date: 2016-01-05 Post Count: 1524 |
You're a idiot shriek. Op this happens when the mouse hits nothing for 1000 units of distance. However your problem specifically is your moving the mouse so fast than from where it checked if mouse moved and if mouse.target and where it is now is no longer true. Use user input service and you'll see this problem go away.
In other works use uis or
Target
If mouse.target then
Target = Mouse.Target |
|
Hedr0nJoin Date: 2016-01-05 Post Count: 1524 |
Actually do something like this
Tar = Mouse.Target
if Tar then
--- do stuff
end |
|
|
local part = game:GetService("ReplicatedStorage"):FindFirstChild("TheBrick"):Clone()
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local pos = mouse.Hit.p
local Tar = mouse.Target
mouse.Move:connect(function()
if Tar then
if Tar.Name == "HOVER_TRUE" then
part.Parent = game:GetService("Workspace")
part.Position = pos
part.Transparency = 0.5
else
if Tar.Name ~= part.Name and "HOVER_TRUE" then
part:remove()
end
end
end
end)
No errors but it's not doing what its post to do. |
|
|
Well, It's not actually doing ANYTHING if I'm being honest. |
|
|
|
|
@otherppl
You do not seem to fully understand Lua, mouse.Hit.p is a value, and does not reference the actual property. mouse.Target references the current Target, but not the property.
Also, "HOVER_TRUE" will always evaluate to true.
|
|
|
Well uh- I'm here to learn haha.
So whats wrong with this?
local part = game.ReplicatedStorage.TheBrick:Clone()
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Move:connect(function()
if mouse.Target then
if mouse.Target.Name == "HOVER_TRUE" then
part.Parent = game.Workspace
part.Position = mouse.Hit.p
part.Transparency = 0.5
else
if mouse.Target.Name ~= part.Name then
part:remove()
end
end
end
end)
I make it check the target but the an error can still come up saying the target does not exist? |
|
|
local part = game.ReplicatedStorage.TheBrick:Clone()
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Move:connect(function()
if mouse.Target then
if mouse.Target.Name == "HOVER_TRUE" then
part.Parent = game.Workspace
part.Position = mouse.Hit.p
part.Transparency = 0.5
else
if mouse.Target then
if mouse.Target.Name ~= part.Name then
part:remove()
end
end
end
end
end)
Fixed it.. I just had to make sure the 'else' checked for Target too. |
|