Hello, I’ve decided to give up trying to fix this issue because I haven’t found how to do it by myself and it has made me quite frustrated, could anyone help me make this code run, check if the player has said cosmetic on themselves and if not then give them the item, but if they do then do nothing.
the issue at the moment is that i don’t know how to make it so it only runs once rather than per each item in the player.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local clickedEvent = ReplicatedStorage:WaitForChild('PillarClicked')
local childChangedEvent = ReplicatedStorage:WaitForChild('childChangedEvent')
local function onClick(player, character, headFolder)
for _, child in (headFolder:GetChildren()) do
local split = child.Name:split("_")
if child:IsA('Model') or child:IsA('Accessory') then
for _, cosmetic in character:GetDescendants() do
if cosmetic:IsA('Model') or cosmetic:IsA('Accessory') then
if cosmetic.Name == child.Name then
print(child.Name, 'found')
else
print(child.Name, 'not found')
local folder = character:FindFirstChild('Unusual_Inventory')
local clone = child:Clone()
local holder = clone:WaitForChild('plh_parent')
childChangedEvent:FireClient(player, child)
clone.Parent = folder
holder.Anchored = true
break
end
end
end
end
end
end
clickedEvent.OnServerEvent:Connect(onClick)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
local player = game.Players:FindFirstChild(hit.Parent.Name)
if player ~= nil and humanoid ~= nil then
local playertool = player.Backpack:FindFirstChild(tooltofind)
local charactertool = humanoid.Parent:FindFirstChild(tooltofind)
if charactertool ~= nil or playertool ~= nil then
print("found tool in player")
end
end
script.Parent.Touched:Connect(function(hit)–when something touches the part
local humanoid = hit.Parent:FindFirstChild("Humanoid")--finds humanoid in hits parent
local player = game.Players:FindFirstChild(hit.Parent.Name)--finding hits parent name(characters name) in players
if player ~= nil and humanoid ~= nil then--if the humanoid isnt nil and the player isnt nol too
local playertool = player.Backpack:FindFirstChild(tooltofind)--finds tool in players backpack
local charactertool = humanoid.Parent:FindFirstChild(tooltofind)--finds tool in character
if charactertool ~= nil or playertool ~= nil then--if the tool was found in players backpack or in the players humanoid
print("found tool in player")--prints just to be sure the tool was found
end
end
I can’t use this in my script since it has nothing to do with .Touched, and its also not this specific since ill be picking multiple items rather than just 1 specific item from 1 specific place
It works for instances amd objects as well, normally it is used with dictionaries, also, the data you give to the loops in generated in dictionary form