[Solved] Need help with this script

  • What do you want to achieve?
    I want the background.Out to be transperency = 0 when it is selected.

  • What is the issue?
    With help of the images you can grasp the problem more better, here they are :-

scren04
the above picture is the layout of the stuff
scren02
the above picture is the layout of the stuff

scren03
the problem looks like above

scren01
this is how I want to achieve but for the flashlight and diamondsword

  • What solutions have you tried so far?
    well i have tried literrally 50 if not 100 times, i mean *LITTERALLY
    to achieve what i wanted welp, couldnt do it though : (
-- local backgroundColor = Color3.fromRGB(255, 255, 255)
local maxOnHotbar = 5 
local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local p = Players.LocalPlayer
local Backpack = p.Backpack
local Character = p.Character
local Frame = script.Parent.Frame
local Template = Frame.Contents.objTemplate
local COLOR_DARKER = 0.65
local KEY_DICTIONARY = { Zero = 10, One = 1, Two = 2, Three = 3, Four = 4, Five = 5, Six = 6, Seven = 7, Eight = 8, Nine = 9 }
local EQUIP_TWEENINFO = TweenInfo.new(0.25, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out)
local items = {}
local tweens = {}
for _, v in Frame.Contents:GetChildren() do
	if v:FindFirstChildOfClass("Frame") then
		v.Background.Out.Transparency = 1
	end
end


local function handleEquip(tool)
	if tool.Parent ~= Character then
		for _, v in Frame.Contents:GetChildren() do
			if v:FindFirstChildOfClass("Frame") then
				v.Background.Out.Transparency = 1
			end
		end
		local instance = Frame.Contents
		for _, Descendant in pairs(instance:GetChildren()) do
			if Descendant:IsA("Frame") then

				if Descendant.Image.Image == nil then
					if Descendant.FixedName.Text == tool.Name then
						Descendant.Background.Out.Transparency = 0
					end
				elseif Descendant.Image.Image ~= nil then 
					if Descendant.Image.Image == tool.TextureId then
						Descendant.Background.Out.Transparency = 0
					end
				end
			end
		end
		Character.Humanoid:EquipTool(tool)
	else
		for _, v in Frame.Contents:GetChildren() do
			if v:FindFirstChildOfClass("Frame") then
				v.Background.Out.Transparency = 1
			end
		end
		Character.Humanoid:UnequipTools()
	end
end






local function checkHotbar(removeIndex)
	if removeIndex then
		for _, toolCircle in pairs(Frame.Contents:GetChildren()) do
			if toolCircle:IsA("GuiObject") then
				if tonumber(toolCircle.Name) >= removeIndex then
					local newIndex = (tonumber(toolCircle.Name) == 11) and 0 or tonumber(toolCircle.Name) - 1
					local isVisible = (maxOnHotbar == 10) and (newIndex <= 9 and true or false) or ((newIndex ~= 0 and newIndex <= maxOnHotbar) and true or false)
					
					toolCircle.LayoutOrder -= 1
					toolCircle.Name -= 1
					toolCircle.Visible = isVisible
					toolCircle.Index.Text = newIndex
					print(isVisible)
				end
			end
		end
	end
	
	local additionalIndex = Frame.AdditionalIndex
	additionalIndex.Size = UDim2.new(0, Frame.Contents.UIListLayout.AbsoluteContentSize.X + Frame.Contents.AbsoluteSize.Y + 15, 0, 25)
	additionalIndex.Text = "+" .. (#items - maxOnHotbar)
	additionalIndex.Visible = (#items > maxOnHotbar)
	
	for index, tool in ipairs(items) do
		local toolCircle = Frame.Contents:FindFirstChild(index)
		local isEquipped = (tool.Parent == Character)
		
		if not toolCircle then
			return
		end
		
		if tweens[toolCircle] then
			tweens[toolCircle]:Cancel()
			tweens[toolCircle] = nil
		end
		
		tweens[toolCircle] = TweenService:Create(toolCircle.Background.In, EQUIP_TWEENINFO, {
			BackgroundTransparency = isEquipped and 0.25 or 0.5
		})
		tweens[toolCircle]:Play()
	end
end

local function create(tool)
	local nextIndex = (#items == 10) and 0 or #items
	local isVisible = (maxOnHotbar == 10) and (nextIndex <= 9 and true or false) or ((nextIndex ~= 0 and nextIndex <= maxOnHotbar) and true or false)
	local toolCircle = Template:Clone()
	toolCircle.LayoutOrder = #items
	toolCircle.Name = #items
	toolCircle.Size = UDim2.new(0, Frame.Contents.AbsoluteSize.Y, 0, Frame.Contents.AbsoluteSize.Y)
	toolCircle.Visible = isVisible
	toolCircle.Image.Image = tool.TextureId
	toolCircle.Index.Text = nextIndex
	toolCircle.FixedName.Text = tool.TextureId == "" and tool.Name or ""
	toolCircle.Parent = Frame.Contents
	toolCircle.Image.MouseButton1Click:Connect(function()
		handleEquip(tool)
	end)
	
	checkHotbar()
end

local function updateAdd(tool)
	if not tool:IsA("Tool") then
		return
	end
	
	checkHotbar()
	
	if table.find(items, tool) then
		return
	end
	
	table.insert(items, tool)
		
	create(tool)
end

local function updateRemove(tool)
	if not tool:IsA("Tool") then
		return
	end
	
	if tool.Parent == Character or tool.Parent == Backpack then
		return
	end
	
	if table.find(items, tool) then
		local index = table.find(items, tool)
		local toolCircle = Frame.Contents:FindFirstChild(index)
		
		if toolCircle then
			toolCircle:Destroy()
		end
		
		table.remove(items, index)
		checkHotbar(index)
	end
end


while true do
	local success, err = pcall(function()
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
	end)
	if success then
		break
	end
	wait()
end

if maxOnHotbar > 10 then
	maxOnHotbar = 10
end
Template.Background.Out.UIGradient.Color = ColorSequence.new(backgroundColor, Color3.new(backgroundColor.R * COLOR_DARKER, backgroundColor.G * COLOR_DARKER, backgroundColor.B * COLOR_DARKER))
Template.Visible = true
Template.Parent = nil
for _, tool in pairs(Backpack:GetChildren()) do
	updateAdd(tool)
end
Backpack.ChildAdded:Connect(updateAdd)
Backpack.ChildRemoved:Connect(updateRemove)
Character.ChildAdded:Connect(updateAdd)
Character.ChildRemoved:Connect(updateRemove)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then
		return
	end
	
	if KEY_DICTIONARY[input.KeyCode.Name] then
		local index = KEY_DICTIONARY[input.KeyCode.Name]
		
		if items[index] then
			handleEquip(items[index])
		end
	end
end)

Pls help me with the folowing,
A fellow developer,
The Spikey Man

2 Likes

Have you tried Out.BackgroundTransparency?

1 Like

does any of it work? I looked over it and I think the .InputBegan function should be replaced by looping over the frame that the gear buttons are in and detecting when each one’s button is clicked. also, when you call the handleequip function it looks like it needs the actual tool instance not a value in a table.

the if statement at the start of the handleequip function is seeing if the value of the items table is a child of the character? it should be character:FindFirstChild(tool) or tool.Name if you change the argument when you call the function to the actual tool.

i’m confused why it’s looping through the contents frame in handleequip when you’re just changing specific things in different ways. i’m also guessing this is a localscript so you should fire a remoteevent for humanoid:equiptool(tool (which again needs to be an actual tool))

my conclusion is I think this whole script is a lot more complicated than it really needs to be lol

1 Like

wdym by that ? isnt it supposed to be Out.Transperency

1 Like

So first of all this is a free model i didnt wrote the script, i just edited some of it which is the HandleEquipTools Function. So ya pls help bro

1 Like

so basically i got gui confused with a part.
for guis it should be visible and not transperency.
sorry for huge mistake.
any moderator there, pls delete the above topic my mistake wont do again

1 Like

So I changed the script and this is the final script. It Works finnaly! ! ! ! ! !

local backgroundColor = Color3.fromRGB(255, 255, 255)
local maxOnHotbar = 5 
local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local p = Players.LocalPlayer
local Backpack = p.Backpack
local Character = p.Character
local Frame = script.Parent.Frame
local Template = Frame.Contents.objTemplate
local COLOR_DARKER = 0.65
local KEY_DICTIONARY = { Zero = 10, One = 1, Two = 2, Three = 3, Four = 4, Five = 5, Six = 6, Seven = 7, Eight = 8, Nine = 9 }
local EQUIP_TWEENINFO = TweenInfo.new(0.25, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out)
local items = {}
local tweens = {}
for _, v in Frame.Contents:GetChildren() do
	if v:FindFirstChildOfClass("Frame") then
		v.Background.Out.Transparency = 1
	end
end


local function handleEquip(tool)
	if tool.Parent ~= Character then
		Character.Humanoid:EquipTool(tool)
	else
		Character.Humanoid:UnequipTools()
	end
end






local function checkHotbar(removeIndex)
	if removeIndex then
		for _, toolCircle in pairs(Frame.Contents:GetChildren()) do
			if toolCircle:IsA("GuiObject") then
				if tonumber(toolCircle.Name) >= removeIndex then
					local newIndex = (tonumber(toolCircle.Name) == 11) and 0 or tonumber(toolCircle.Name) - 1
					local isVisible = (maxOnHotbar == 10) and (newIndex <= 9 and true or false) or ((newIndex ~= 0 and newIndex <= maxOnHotbar) and true or false)
					
					toolCircle.LayoutOrder -= 1
					toolCircle.Name -= 1
					toolCircle.Visible = isVisible
					toolCircle.Index.Text = newIndex
					print(isVisible)
				end
			end
		end
	end
	
	local additionalIndex = Frame.AdditionalIndex
	additionalIndex.Size = UDim2.new(0, Frame.Contents.UIListLayout.AbsoluteContentSize.X + Frame.Contents.AbsoluteSize.Y + 15, 0, 25)
	additionalIndex.Text = "+" .. (#items - maxOnHotbar)
	additionalIndex.Visible = (#items > maxOnHotbar)
	
	for index, tool in ipairs(items) do
		local toolCircle = Frame.Contents:FindFirstChild(index)
		local isEquipped = (tool.Parent == Character)
		
		if not toolCircle then
			return
		end
		
		if tweens[toolCircle] then
			tweens[toolCircle]:Cancel()
			tweens[toolCircle] = nil
		end
		
		tweens[toolCircle] = TweenService:Create(toolCircle.Background.In, EQUIP_TWEENINFO, {
			BackgroundTransparency = isEquipped and 0.25 or 0.5
		})
		tweens[toolCircle] = TweenService:Create(toolCircle.Background.Out, EQUIP_TWEENINFO, {
			BackgroundTransparency = isEquipped and 0 or 1
		})
		tweens[toolCircle]:Play()
	end
end

local function create(tool)
	local nextIndex = (#items == 10) and 0 or #items
	local isVisible = (maxOnHotbar == 10) and (nextIndex <= 9 and true or false) or ((nextIndex ~= 0 and nextIndex <= maxOnHotbar) and true or false)
	local toolCircle = Template:Clone()
	toolCircle.LayoutOrder = #items
	toolCircle.Name = #items
	toolCircle.Size = UDim2.new(0, Frame.Contents.AbsoluteSize.Y, 0, Frame.Contents.AbsoluteSize.Y)
	toolCircle.Visible = isVisible
	toolCircle.Image.Image = tool.TextureId
	toolCircle.Index.Text = nextIndex
	toolCircle.FixedName.Text = tool.TextureId == "" and tool.Name or ""
	toolCircle.Parent = Frame.Contents
	toolCircle.Image.MouseButton1Click:Connect(function()
		handleEquip(tool)
	end)
	
	checkHotbar()
end

local function updateAdd(tool)
	if not tool:IsA("Tool") then
		return
	end
	
	checkHotbar()
	
	if table.find(items, tool) then
		return
	end
	
	table.insert(items, tool)
		
	create(tool)
end

local function updateRemove(tool)
	if not tool:IsA("Tool") then
		return
	end
	
	if tool.Parent == Character or tool.Parent == Backpack then
		return
	end
	
	if table.find(items, tool) then
		local index = table.find(items, tool)
		local toolCircle = Frame.Contents:FindFirstChild(index)
		
		if toolCircle then
			toolCircle:Destroy()
		end
		
		table.remove(items, index)
		checkHotbar(index)
	end
end


while true do
	local success, err = pcall(function()
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
	end)
	if success then
		break
	end
	wait()
end

if maxOnHotbar > 10 then
	maxOnHotbar = 10
end
Template.Background.Out.UIGradient.Color = ColorSequence.new(backgroundColor, Color3.new(backgroundColor.R * COLOR_DARKER, backgroundColor.G * COLOR_DARKER, backgroundColor.B * COLOR_DARKER))
Template.Background.In.UIGradient.Color = ColorSequence.new(backgroundColor, Color3.new(backgroundColor.R * COLOR_DARKER, backgroundColor.G * COLOR_DARKER, backgroundColor.B * COLOR_DARKER))
Template.Visible = true
Template.Parent = nil
for _, tool in pairs(Backpack:GetChildren()) do
	updateAdd(tool)
end
Backpack.ChildAdded:Connect(updateAdd)
Backpack.ChildRemoved:Connect(updateRemove)
Character.ChildAdded:Connect(updateAdd)
Character.ChildRemoved:Connect(updateRemove)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then
		return
	end
	
	if KEY_DICTIONARY[input.KeyCode.Name] then
		local index = KEY_DICTIONARY[input.KeyCode.Name]
		
		if items[index] then
			handleEquip(items[index])
		end
	end
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.