Script gives an error every time I move the mouse

Every time I move my mouse over something it prints the error Players.Coder_Tom.PlayerScripts.mainPickup:73: attempt to index nil with ‘Name’

local validTargets = {
‘Leaf’,
‘Leaves’,
‘PinkPlant’
}

UIS.InputBegan:Connect(function(input, gpe)
if (gpe) then return end

if (table.find(validTargets, mouse.Target.Name) or table.find(validTargets, mouse.Target.Parent.Name)) then
if (input.UserInputType == Enum.UserInputType.Keyboard) then
if (input.KeyCode == Enum.KeyCode[key]) then
local randomLeaves = math.random(1, 4)
local randomPetals = math.random(1, 4)
replicatedStorage.EnviromentEvents.Fibre:FireServer(randomLeaves, randomPetals)
end
end
end
end)

It seems like your validTargets array is using incorrect syntax. Strings have to be surrounded by pairs of ’ or ", not ‘. When I put your code in my Studio editor it doesn’t identify the contents of that array as strings, it instead prints an error.

1 Like