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

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

Asked by 4 years ago

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)
0
You want the player to claim the tool only once even if equipped or unequipped? XviperIink 428 — 4y
0
I would edited this but your code is very hard to read and I don't understand it voidofdeathfire 148 — 4y
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. Axemurderer27 -3 — 4y

1 answer

Log in to vote
0
Answered by
Farsalis 369 Moderation Voter
4 years ago
Edited 4 years ago

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)
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. Axemurderer27 -3 — 4y
0
Oh, you want to take multiple? Farsalis 369 — 4y
0
I though you meant One Farsalis 369 — 4y
0
Edited :) should work for both. Farsalis 369 — 4y
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. Axemurderer27 -3 — 4y
Ad

Answer this question