You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I wanna be able to reset and set new mouse.target(variable is target) without attempted to index nil with .touched error appearing
- What is the issue? Include screenshots / videos if possible!
I have a telekinesis script and I when I throw the object with 2 any other mouse.targets that ive already made will be thrown too. So I added a mouse.target = nil so the mouse.target would reset, but then after I pick up a second thing the error, attemped to index nil with .touched appears in the output.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried looking up solutions on google chrome and on dev hub, they were either confusing, or didn’t work.
Server Script; If you need to see the Local Script you can ask
target.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= player.Name then
if isGoing == false then
isGoing = true
local eneH = hit.Parent.Humanoid
local found
for _, character in next, hitE do
if character == eneH then
-- some boolean toggle for match
found = true
end
end
if not found then
table.insert(hitE, eneH)
end
eneH:TakeDamage(30)
wait(.5)
for i, character in next, hitE do
if character == eneH then
table.remove(hitE, i)
end
end
end
end
end)
wait(.05)
isGoing = false
BV:Destroy()
target = nil
TKStart:FireClient(player)
end)
end)
TKEnd.OnServerEvent:Connect(function(player)
Anim:Stop()
HoldGrip:Destroy()
attachment0:Destroy()
BG:Destroy()
BV0:Destroy()
target = nil
TKStart:FireClient(player)
end)
To recap, I want to be able to fix the attempted to index nil with .touched error but still be able to reset mouse.target(variable is target) and set a new one.