I've been trying my best to make a GUI with weapon equip options. However, the weapons in the game must be found via Badge collection. So once the badge for the weapon is found, you should be able to click on the GUI button and equip it to the players inventory, if it isn't found then the equip button should be disabled. I'm confident I'm just following the wrong guidelines to make it, any options for this?
My sad attempt ~
ID = 158694379 badge = game:GetService("BadgeService") player = script.Parent.Parent.Parent.Parent.Parent function find(userid, badgeid) if game:GetService("BadgeService"):UserHasBadge(userid, badgeid) then clone = game.Lighting.GravityCoil:clone() clone.Parent = player.StarterGear end end function MouseClick(hit) if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then local p = game.Players:GetPlayerFromCharacter(hit.Parent) if (p ~= nil) then if (find(p.userId, badgeholder.Value)) then clone = game.Lighting.GravityCoil:clone() clone.Parent = player.StarterGear elseif (find(p.userId, badgeholder.Value) == false) then hit.Parent.MouseButton1Click:remove() end end script.Parent.MouseButton1Click:connect(MouseClick)
The main problems: MouseButton1Click doesn't return any parameters, hit is mainly for touched events; putting the grav coil clone into StarterGear requires the player to die before obtaining the gear, which I assume to be undesired; if the MouseClick function worked, by calling the find function, the player will receive the gear twice.
local ID = 158694379 --Local variables are generally better practice because they allow for faster lookup and limit variable clutter between functions local badge = game:GetService("BadgeService") local player = game.Players.LocalPlayer --an alternative for getting the player only in local scripts function find(userid, badgeid) if badge :UserHasBadge(userid, badgeid) then return true --replaces wherever the function was called with the bool "true" else return false --same as above with "false end end function MouseClick() --if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then --this line and the two following lines are unnecessary when using a gui --local p = game.Players:GetPlayerFromCharacter(hit.Parent) --if (p ~= nil) then --and if you are using this, then "if p then" is fine. If p is nil, it'll return nil or false and not run the code under that if statement. if (find(player.userID, ID)) then local clone = game.ReplicatedStorage.GravityCoil:clone() --ReplicatedStorage was designed to replace lighting as a storage box for items that need to be accessed by a client. I suggest putting the gravity coil there. local clone2 = game.ReplicatedStorage.GravityCoil:clone() clone.Parent = player.Backpack --adding it to the backpack and StarterGear gives the player the gear immediately and allows the player to keep it every time they die. By omitting the backpack in your original code, you require the player to die before obtaining the gear. clone2.Parent = player.StarterGear else script.Parent.MouseButton1Click:Destroy() --remove() is depreciated and I took out p --script.Parent.BackgroundColor3 = Color3.New(.5, .5, .5) --The color is intended to be a darker shade of the normal background color of the button. This is suggested so that the player will know what they can get, and to reduce the amount of work required to make sure that the guis appear as intended. end end script.Parent.MouseButton1Click:connect(MouseClick)
Or, condensed to one function (minus comments)
local ID = 158694379 local badge = game:GetService("BadgeService") local player = game.Players.LocalPlayer function find(userid, badgeid) if badge :UserHasBadge(userid, badgeid) then local clone = game.ReplicatedStorage.GravityCoil:clone() local clone2 = game.ReplicatedStorage.GravityCoil:clone() clone.Parent = player.Backpack clone2.Parent = player.StarterGear else script.Parent.MouseButton1Click:Destroy() --script.Parent.BackgroundColor3 = Color3.New(.5, .5, .5) end end script.Parent.MouseButton1Click:connect(function() find(player.userId, ID) end)