Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[] Been Asked 15 times, no one knows how [] Impossible Weapon Gui to create?

I've been trying my best to make a GUI with weapon equip options. However, the weapons in the game should only be accessed if the player has the certain badge collected. So once the badge for the weapon is found, you should be able to click on the GUI button and equip it to your 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)

1 comment

0

Stop Duplicating Questions or they will be shut down and closed. Just ask it once.

2 answers

This isn't even syntactically valid. Since your tabbing is so wrong, you don't catch that you have too many ifs for the number of ends you have.


GUI objects don't have a "hit" parameter that tells you the part touching them... That doesn't make sense, parts don't touch them.

The parameter is a location, which is not relevant in this case.


The relevant player would be specified as script.Parent.Parent.... etc.

That would be your p -- in fact, you already have the variable -- player.


There's no reason to say if X then ... elseif not X then. Just use else.


You call a function in an if asking whether they have the badge. If they do, you give them the weapon... But that function actually doesn't return whether or not they have the badge, and it just goes ahead and gives them the weapon.


Also, tab your code reasonably. And name your names reasonably.


This is overall an example of a badly made script. Slow down, think about what you're doing, and keep it simple. There should be a very good reason to include every single word in your script. If you can do it with fewer, you almost always should.

gravityBadge = 158694379
badgeservice = game:GetService("BadgeService")
player = script.Parent.Parent.Parent.Parent.Parent

function hasbadge(player, badgeid)
	return badgeservice:UserHasBadge(player.userId, badgeid)
end

function MouseClick()
	if hasbadge(player, gravityBadge) then
		local clone = game.Lighting.GravityCoil:Clone()
		clone.Parent = player.StarterGear
	end
end
script.Parent.MouseButton1Click:connect(MouseClick)

I don't know, but people does say not to ask the same question over and over again since it is like spamming. I did that once and I got locked for no reason (sort of) :D

This discussion is preserved as it was. New answers, comments, and votes are closed.