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

Why is my giver only allowing me to claim the tool once if it is already in my inventory?

I am able to claim my tool as long as I don't already have it in my inventory, I know it has something to do with the backpack == nil but I just can't find another solution around it.

Imgur

local toolName = script.Parent.Parent.ToolValue.Value
local count = script.Parent.Parent.Count.Value
local amount = script.Parent.Parent.Amount.Value
counter = amount

function onMouseClick(player)
	if player:IsInGroup(4893229) then
		if player.Backpack:FindFirstChild(toolName) == nil then
	if script.Parent.Parent.Count.Value > 0 then
		local tool = game.Lighting[toolName]:Clone()
		tool.Parent = player.Backpack
		script.Parent.Parent.Count.Value = script.Parent.Parent.Count.Value - 1
		script.Parent.Parent.Surface.SurfaceGui.TextLabel.Text = tostring(script.Parent.Parent.Count.Value).."/"..tostring(amount)
		--script.Parent.Parent.BillboardGui.TextLabel.Text = tostring(count).."/20"
	end
		end
	end
	end
script.Parent.MouseClick:connect(onMouseClick)

3 comments

0

You want the player to claim the tool only once even if equipped or unequipped?

0

I would edited this but your code is very hard to read and I don't understand it

0

Sorry about it being all over the place but, Yes I want them to be able to take multiple of the tool and not just one.

1 answer

✓ Accepted answer

Why Do You Have So Many Values In You Model? Instead Of The Script?

Anyways, this should work:

local toolName = script.Parent.Parent.Name -- Whatever Name You Want It To BE
local count = 0 -- Whatever Number You Want It At
local amount =	"" -- Whatever You Want It To Be
local tool = game.Lighting[toolName]:Clone()
counter = amount

function onMouseClick(player)
  if player:IsInGroup(4893229) then
	print(player)
    if not player.Backpack:FindFirstChild(toolName) and count >= 0 then
	        tool.Parent = player.Backpack
	      	count = count - 1
	        script.Parent.Parent.Surface.SurfaceGui.TextLabel.Text = tostring(count).."/"..tostring(amount)
	        script.Parent.Parent.BillboardGui.TextLabel.Text = tostring(count).."/20"

   elseif player.Backpack:FindFirstChild(toolName) and count < 0 then
		tool.Parent = player.Backpack
	      	count = count - 1
	        script.Parent.Parent.Surface.SurfaceGui.TextLabel.Text = tostring(count).."/"..tostring(amount)
	        script.Parent.Parent.BillboardGui.TextLabel.Text = tostring(count).."/20"
        end
    end
end

script.Parent.MouseClick:connect(onMouseClick)

5 comments

0

But this still doesn't allow me to be able to take multiple of the tool because you're checking to see if it's already in the inventory.

0

Oh, you want to take multiple?

0

I though you meant One

0

Edited :) should work for both.

0

It didn't work for me but it might of been because of all my values but I did find another way around it though. Appreciate the support.

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