Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Impossible GUI to create?

Asked by 10 years ago

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 ~

01ID = 158694379
02badge = game:GetService("BadgeService")
03player = script.Parent.Parent.Parent.Parent.Parent
04 
05function find(userid, badgeid)
06if game:GetService("BadgeService"):UserHasBadge(userid, badgeid) then
07    clone = game.Lighting.GravityCoil:clone()
08    clone.Parent = player.StarterGear
09    end
10end
11 
12function MouseClick(hit)
13    if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then
14        local p = game.Players:GetPlayerFromCharacter(hit.Parent)
15        if (p ~= nil) then
View all 23 lines...

1 answer

Log in to vote
0
Answered by 10 years ago

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.

01local ID = 158694379 --Local variables are generally better practice because they allow for faster lookup and limit variable clutter between functions
02local badge = game:GetService("BadgeService")
03local player = game.Players.LocalPlayer --an alternative for getting the player only in local scripts
04 
05function find(userid, badgeid)
06    if badge :UserHasBadge(userid, badgeid) then
07        return true --replaces wherever the function was called with the bool "true"
08    else return false --same as above with "false
09    end
10end
11 
12function MouseClick()
13    --if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then --this line and the two following lines are unnecessary when using a gui
14    --local p = game.Players:GetPlayerFromCharacter(hit.Parent)
15    --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.
View all 27 lines...

Or, condensed to one function (minus comments)

01local ID = 158694379
02local badge = game:GetService("BadgeService")
03local player = game.Players.LocalPlayer
04 
05function find(userid, badgeid)
06    if badge :UserHasBadge(userid, badgeid) then
07        local clone = game.ReplicatedStorage.GravityCoil:clone()
08        local clone2 = game.ReplicatedStorage.GravityCoil:clone()
09        clone.Parent = player.Backpack
10        clone2.Parent = player.StarterGear
11    else
12        script.Parent.MouseButton1Click:Destroy()
13        --script.Parent.BackgroundColor3 = Color3.New(.5, .5, .5)
14    end
15end
16 
17script.Parent.MouseButton1Click:connect(function() find(player.userId, ID) end)
0
The scripts you provided seem very reasonable but they don't appear to work. I've placed the script within a local script and then placed it within an ImageButton in my GUI. Once I entered the game and tested it, nothing happened. My profile obviously has the badge, I made sure it was the correct badge ID too. I made sure the GravityCoil was in the ReplicatedStorage as well. Does it have something HurricaneOtto 0 — 10y
0
Does it have something to do with the script being local? Will it not allow badges that aren't created for the game the script is within? I was hoping that it would allow that as the game is really 5 games conjoined into one. Is there a way to fix this? HurricaneOtto 0 — 10y
0
I just checked the wiki and it said that the badge service can only be used in a script. GoldenPhysics 474 — 10y
0
I already knew that. But does it have something to do with the badge not being created for the game the script is in? I'm only asking because the script doesn't work. HurricaneOtto 0 — 10y
Ad

Answer this question