So,what I had in my mind is making a weapon wheel with different weapon categories (such as assault rifles,shotguns,handguns,etc),something similar to the weapon wheels in gta games.
This weapon wheel is made of multiple frames that form the shape of a circle,each one represents a different gun category and uppon clicking on them the player will equip the gun,the script will filter the gun by categories by finding a child on it,the child will be a part inside the gun(tool) that will have the name of the gun category (for example shotguns will have a part with the name shotgun).
After that it will add a image label with the gun image to the frame where it belongs to,when clicking the frame the script will fire a remote event that will cause the player to equip the chosen gun.
The problem comes when I test the script and press right click to active the weapon wheel,the image labels don’t show up,I still can move the pointer that chosses the gun but nothing happens when I click the frame where the testing pistol is supposed to be at.
Something to take in considerations is that I copied this script from youtube,I just cut some parts that I did’nt liked,changed the UI,tried to add the weapon category idea and edited it,this means that I don’t know how some of the script parts work.
--------------Turns off the default backpack gui------------------
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
---------Turns off the gui when joining the game-------------------
script.Parent.Enabled = false
local rs = game:GetService("RunService")
local uis = game:GetService("UserInputService")
local mouse = game.Players.LocalPlayer:GetMouse()
local camera = workspace.CurrentCamera
local currentlyHovering = nil
local count = 0
local pointer = script.Parent:WaitForChild("Pointer")
local frame = script.Parent:WaitForChild("InventoryFrame")
local circumference = frame.AbsoluteSize.X * math.pi
------------------Closing and opening the UI when pressing right click---------------
uis.InputBegan:Connect(function(inp, p)
if inp.UserInputType == Enum.UserInputType.MouseButton2 and not p then
script.Parent.Enabled = not script.Parent.Enabled
end
end)
function updateSectors()
---------------------------------tools(guns yes)-------------------------------------------------------------
local tools = game.Players.LocalPlayer.Backpack:GetChildren()
----------------------------------------------------------------------------------------------
if game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool") then
table.insert(tools, game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool"))
end
count = #tools
----------------------------------------------------------------------------------------------
table.sort(tools, function(a, b)
return a.Name < b.Name
end)
local absoluteSectorWidth = (circumference / count)
local sectorWidth = absoluteSectorWidth / frame.AbsoluteSize.X
----------------------------------------------Frames of the weapon wheel variables----------------------------------------------------
for i, tool in pairs(tools) do
local pistolSector = script.Parent.GunWheelPistol -- Pistols
local SubmachinegunsSector = script.Parent.GunWheelSubMachineGuns -- Submachineguns
local AssaultRiflesSector = script.Parent.GunWheelAssaultRifles -- AssaultRifles
local ShotgunsSector = script.Parent.GunWheelShotguns -- Shotguns
local HeavySector = script.Parent.GunWheelHeavyGuns -- HeavyGuns
local SpecialSector = script.Parent.GunWheelSpecials -- SpecialGuns
local MeleeSector = script.Parent.GunWheelMelee -- Melee
---------------------------------------------------------------------------------------------------
local rotation = (i-1) * (360/count)
---------------------------------------------------------------------------------------------------
if tool:FindFirstChild("Pistol") then --------------------------------- Pistols
local PistolDisplay = Instance.new("ImageLabel")
PistolDisplay.Parent = pistolSector
PistolDisplay.Name = "PistolDisplay"
PistolDisplay.Image = tool.TextureId
elseif tool:FindFirstChild("Submachinegun") then ---------------------- Submachineguns
local SubDisplay = Instance.new("ImageLabel")
SubDisplay.Parent = SubmachinegunsSector
SubDisplay.Name = "PistolDisplay"
SubDisplay.Image = tool.TextureId
elseif tool:FindFirstChild("Assault") then ----------------------------- Asauult Rifles
local AssaultDisplay = Instance.new("ImageLabel")
AssaultDisplay.Parent = AssaultRiflesSector
AssaultDisplay.Name = "PistolDisplay"
AssaultDisplay.Image = tool.TextureId
elseif tool:FindFirstChild("Shotgun") then ---------------------------- Shotguns
local ShotgunDisplay = Instance.new("ImageLabel")
ShotgunDisplay.Parent = ShotgunsSector
ShotgunDisplay.Name = "PistolDisplay"
ShotgunDisplay.Image = tool.TextureId
elseif tool:FindFirstChild("Heavy") then -------------------------------- Heavy Guns
local HeavyDisplay = Instance.new("ImageLabel")
HeavyDisplay.Parent = HeavySector
HeavyDisplay.Name = "PistolDisplay"
HeavyDisplay.Image = tool.TextureId
elseif tool:FindFirstChild("Special") then ------------------------------ Special Guns
local SpecialDisplay = Instance.new("ImageLabel")
SpecialDisplay.Parent = HeavySector
SpecialDisplay.Name = "PistolDisplay"
SpecialDisplay.Image = tool.TextureId
elseif tool:FindFirstChild("Melee") then
local MeleeDisplay = Instance.new("ImageLabel") ----------------- Melee Weapons
MeleeDisplay.Parent = MeleeSector
MeleeDisplay.Name = "PistolDisplay"
MeleeDisplay.Image = tool.TextureId
end
local toolValue = Instance.new("StringValue")
toolValue.Name = "TOOL NAME"
toolValue.Value = tool.Name
toolValue.Parent = pistolSector
end
end
---------------------Calling the function-------------------------
updateSectors()
game.Players.LocalPlayer.Backpack.ChildAdded:Connect(updateSectors)
game.Players.LocalPlayer.Backpack.ChildRemoved:Connect(updateSectors)
game.Players.LocalPlayer.Character.ChildAdded:Connect(updateSectors)
game.Players.LocalPlayer.Character.ChildRemoved:Connect(updateSectors)
------------------------------------Equip the choosed gun on click----------------------------------
mouse.Button1Up:Connect(function()
if currentlyHovering and script.Parent.Enabled == true then
game.ReplicatedStorage:WaitForChild("InventoryRE"):FireServer(currentlyHovering["TOOL NAME"].Value)
script.Parent.Enabled = false
end
end)
--------------Rotate the pointer and check which tool the player is hovering on,this part works fine already-----------
rs.Stepped:Connect(function()
if count > 0 and script.Parent.Enabled == true then
local x, y = mouse.X, mouse.Y
local viewportSize = camera.ViewportSize / 2
local angle = math.deg(math.atan2(y - viewportSize.Y, x - viewportSize.X)) - 90
if angle < 0 then
angle = angle + 360
end
pointer.Rotation = angle
local space = 360/count/2
for i = 1, count do
local degrees = (i-1) * (360/count)
local min = degrees - space
local max = degrees + space
if min < 0 then
min = min + 360
end
end
end
end)
This is the remote event script
local re = game.ReplicatedStorage:WaitForChild("InventoryRE")
--Equip tool on client request
re.OnServerEvent:Connect(function(player, toolName)
if player.Character and toolName then
if player.Backpack:FindFirstChild(toolName) then
player.Character.Humanoid:EquipTool(player.Backpack[toolName])
elseif player.Character:FindFirstChild(toolName) then
player.Character.Humanoid:UnequipTools()
end
end
end)