Im trying to make this system which will take a tool from the player and put it in a cubby, but it keeps taking the tool but erroring when untransparenting it?
script.Parent.Triggered:Connect(function(player)
if script.Parent.Parent.Parent.GunName.Value == "" then
local char = player.Character
local tool = char:FindFirstChildOfClass("Tool")
if tool.Name == "Glock" or "M1911" or "Serbu Shorty" or "MAC-10" or "Unica 6" or "GlockSwitchDrum" or "GlockSwitch" or "Draco" or "Hi-Point" then
char:FindFirstChild(tool.Name):Destroy()
script.Parent.Parent.Parent.GunName.Value = tool.Name
local modeltool = script.Parent.Parent.Parent.Model:FindFirstChild(tool.Name)
for i,v in pairs(modeltool:GetChildren()) do
i.Transparency = 0
end
else
end
else
if script.Parent.Parent.Parent.GunName.Value ~= "" then
local char = player.Character
local gun = game.ServerStorage:FindFirstChild(script.Parent.Parent.Parent.GunName.Value):Clone()
gun.Parent = player.Backpack
for i,v in pairs(script.Parent.Parent.Parent.Model:FindFirstChild(script.Parent.Parent.Parent.GunName.Value):GetChildren()) do
i.Transparency = 1
script.Parent.Parent.Parent.GunName.Value = ""
end
end
end
end)
script.Parent.Triggered:Connect(function(player)
if script.Parent.Parent.Parent.GunName.Value == "" then
local char = player.Character
local tool = char:FindFirstChildOfClass("Tool")
if tool.Name == "Glock" or "M1911" or "Serbu Shorty" or "MAC-10" or "Unica 6" or "GlockSwitchDrum" or "GlockSwitch" or "Draco" or "Hi-Point" then
char:FindFirstChild(tool.Name):Destroy()
script.Parent.Parent.Parent.GunName.Value = tool.Name
local modeltool = script.Parent.Parent.Parent.Model:FindFirstChild(tool.Name)
for i,v in pairs(modeltool:GetChildren()) do
v.Transparency = 0
end
end
elseif script.Parent.Parent.Parent.GunName.Value ~= "" then
local char = player.Character
local gun = game.ServerStorage:FindFirstChild(script.Parent.Parent.Parent.GunName.Value):Clone()
gun.Parent = player.Backpack
for i,v in pairs(script.Parent.Parent.Parent.Model:FindFirstChild(script.Parent.Parent.Parent.GunName.Value):GetChildren()) do
v.Transparency = 1
script.Parent.Parent.Parent.GunName.Value = ""
end
end
end)
The issue is that i is the index, not the object. Use v instead. (I fixed it in the script)