Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

How do i detect if a Block/Gui is Cloned?

Asked by 1 year ago
Edited 1 year ago

I was working on lucky block

script.Parent.Click1.MouseClick:Connect(function()
    script.Parent.Parent.Parent = game.ReplicatedStorage.Crates
    wait(2)
    script.Parent.Parent.Parent = workspace
end)


local Weapon1 = game.ReplicatedStorage.Tools.Colorless 
local Weapon2 = game.ReplicatedStorage.Tools.MagicalStaff 
local Weapon3 = game.ReplicatedStorage.Tools.SaturnStaff 
local Weapon4 = game.ReplicatedStorage.Tools.Determinator 

local Items = {
    {Weapon1,1},
    {Weapon2,4},
    {Weapon3,5},
    {Weapon4,3} 
}
local TotalWeight = 0

for _,ItemData in pairs(Items) do
    TotalWeight = TotalWeight + ItemData[2]
end

local function chooseRandomItem()
    local Chance = math.random(1,TotalWeight)
    local Counter = 0
    for _,ItemData in pairs(Items) do
        Counter = Counter + ItemData[2]
        if Chance <= Counter then
            return ItemData[1]
        end
    end
end

local click = script.Parent.Click1

click.MouseClick:Connect(function(plr)
    local Tool = chooseRandomItem()
    local CloneTool = Tool:Clone()
    local Gui = script.Text
    local CloneGui = Gui:Clone()

    if plr.Backpack:FindFirstChild(CloneTool.Name) then
        plr.Backpack:FindFirstChild(CloneTool.Name)
        CloneGui.Parent = plr.PlayerGui
        wait(2)
        CloneGui:Destroy()
    else
        CloneTool.Parent = plr.Backpack
    end
end)

I want to do something that if player has the weapon, he wont get it, but that works perfectly, the Gui appear workly, but when destroying the gui that has text of "You Received Weapon That you Already Had" but the Cloned Gui Isnt Getting DESTROYED

The ClickDetector is named "Click1"

Please help!

I Appreaciate It!

1 answer

Log in to vote
0
Answered by 1 year ago

If you are sure that things inside if statement is executed, parenting cloneGui for example, then there is not many reasons why it shouldn't be working

Try using

CloneGui.Parent = nil 

Instead

Ad

Answer this question