local folder = workspace.Collectibles for _,v in pairs(folder:GetChildren()) do local Collectible = v Collectible.Touched:Connect(function(hit) Collectible.BrickColor = BrickColor.new("White") Collectible.Transparency = 0.3 if Collectible.Name == "Collectible1" then local plr = game.Players:GetPlayerFromCharacter(hit.Parent) plr.PlayerGui.UI.Script1.ImageTransparency = 0 end end) end
Hello, I don't really understand what you're trying to do but please try this. I added a guard clause so the codes below would only get executed when what hit Collectible
is a player. Feel free to comment if it ends up not being what you are trying to accomplish.
local folder = workspace.Collectibles for _,v in pairs(folder:GetChildren()) do local Collectible = v Collectible.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if not plr then return end --guard clause Collectible.BrickColor = BrickColor.new("White") Collectible.Transparency = 0.3 if Collectible.Name == "Collectible1" then plr.PlayerGui.UI.Script1.ImageTransparency = 0 end end) end