So I have a for loop iterating through numItems and I’m searching a table to see if a gladius (the target from mouse) is inside the items table, but for some reason this isn’t evaluating as true and proceeding with the code even though the item IS in the table.
--This script's job is going to be making what happens when the player walks up to any item in the game
--that the player can pick up. Shields, Swords, Helmets, Wood, Ores, NPCs, interactable objects, etc.
--The interaction insignia will be updated every frame to the mouse position on the screen, and we'll
--make it visible if the player's mouse is hovering over an item that can be interacted with
local UserInputService = game:GetService('UserInputService')
local RunService = game:GetService('RunService')
local Player = game.Players.LocalPlayer
local playerMouse = Player:GetMouse()
local interaction = script.Parent:WaitForChild('InteractionInsignia')
local PickupItemRemote = game.ReplicatedStorage:WaitForChild('PickupItem')
local ItemName = interaction.ItemName
local Items = {} --this is gonna be a table updated on runservice checking the environment assets folder in a forinpairs loop, inserting any child which is not already apart of the table into the table
local EnvironmentAssets = game.Workspace.EnvironmentAssets:GetChildren()
local insideInteraction = false;
--We're going to display the mouse's visibility based on if the player's mouse is on a specific item in game
--if the player's mouse's hit's position's target's name belongs to an index of the Items table, make
--visible the interaction insignia
playerMouse.Move:Connect(function()
interaction.Position = UDim2.new(0,playerMouse.X,0,playerMouse.Y)
end)
function toggleInteraction(target)
warn('hohohohohhohohoho');
print(target)
for i=1, #Items do
if table.find(Items, target.Parent) or table.find(Items, target) then
warn("Hey boy")
interaction.Visible = true
ItemName.Text = target.Parent.Name
else
interaction.Visible = false
end
end
end
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
local target = ''
target = playerMouse.Target or playerMouse.Target.Parent
if input.KeyCode == Enum.KeyCode.E and table.find(Items, target.Parent) or target.Name == 'Sheathe' or target.Name == 'SheathAccents' or target.Name == 'Hilt' then
PickupItemRemote:FireServer(target)
end
end
end)
RunService.RenderStepped:Connect(function(dt)
--Putting items in table
for i,v in pairs(game.Workspace.EnvironmentAssets:GetChildren()) do
if not table.find(Items, v) then
table.insert(Items, v)
end
end
if playerMouse.Target and Player.PlayerGui.ScreenGui.InventoryWindow.Visible == false then
local target = ''
target = playerMouse.Target or playerMouse.Target.Parent
print(Items)
print(target)
print(target.Parent)
toggleInteraction(target)
end
end)
--now we need to make it so that when the player has a target and if they press e then it will destroy the part
--and put it into their inventory.
Why?