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

MouseButton1Click is not working. Please help. I do not know what the problem is. Anyone?

Asked by 4 years ago

I am trying to make an equip system. Specifacally, for pets. The MouseButton1Click event is not working. Please help.

This is the script

local function createFrame(name, equippedValue)
    local clone = temp:Clone()
    clone.Name = name
    if game.ReplicatedStorage.Pets:FindFirstChild(name) then
        local VPFObj = game.ReplicatedStorage.Pets[name]:Clone()
        VPFObj.Parent = clone

        local fakeCam = Instance.new("Camera")
        fakeCam.Name = "FakeCam"
        fakeCam.CFrame = CFrame.new(VPFObj.PrimaryPart.Position + (VPFObj.PrimaryPart.CFrame.lookVector * 5), VPFObj.PrimaryPart.Position)

        clone.CurrentCamera = fakeCam

        clone.PetName.Text = name

        if equippedValue == "Equipped" then
            clone.Equipped.Text = "Equipped"
            clone.Equip.Text = "Equipped"
            clone.Equipped.TextColor3 = Color3.fromRGB(105, 247, 98)
            elseif equippedValue == "Unequipped" then
                clone.Equipped.Text = "Unequipped"
                clone.Equip.Text = "Unequipped"
                clone.Equipped.TextColor3 = Color3.fromRGB(247, 58, 58)     
            end

        clone.Parent = script.Parent.Pets

        print(clone.Parent.Name)

        return clone

    end


end


local newFrame
local stringValues = game.ReplicatedStorage[folderName].PetsInventory:GetChildren()
if #stringValues > 0 then
    for _, value in pairs(stringValues) do
        if value:IsA("StringValue") and game.ReplicatedStorage.Pets:FindFirstChild(value.Name) then
            if game.ReplicatedStorage[folderName].EquippedPet.Value == value.Name then
                newFrame = createFrame(value.Name, "Equipped")
            else
                newFrame = createFrame(value.Name, "Unequipped")
            end
        end
    end
end

local currentNewFrame

game.ReplicatedStorage.CreatePetFrame.OnClientEvent:Connect(function(name)
    currentNewFrame = createFrame(name, "Unequipped")
end)

repeat wait() until currentNewFrame ~= nil and newFrame ~= nil

currentNewFrame:FindFirstChild("Equip").MouseButton1Click:Connect(function()
    print("Function ran")
    local otherCloneFrames = script.Parent.Pets:GetChildren()
    if #otherCloneFrames > 0 then
        for _, clone in pairs(otherCloneFrames) do
            if not clone:IsA("UIGridLayout") then
                clone.Equipped.Text = "Unequipped"
                clone.Equip.Text = "Unequipped"
                clone.Equipped.TextColor3 = Color3.fromRGB(247, 58, 58)
            end
        end
    end
    print("Got to this line")
    currentNewFrame.Equipped.Text = "Equipped"
    currentNewFrame.Equip.Text = "Equipped"
    currentNewFrame.Equipped.TextColor3 = Color3.fromRGB(105, 247, 98)
    game.ReplicatedStorage[folderName].EquippedPet.Value = currentNewFrame.Name
    print("Changed Value to "..(game.ReplicatedStorage[folderName].EquippedPet.Value))
end)

newFrame:FindFirstChild("Equip").MouseButton1Click:Connect(function()
    local otherCloneFrames = script.Parent.Pets:GetChildren()
    if #otherCloneFrames > 0 then
        for _, clone in pairs(otherCloneFrames) do
            if not clone:IsA("UIGridLayout") then
                clone.Equipped.Text = "Unequipped"
                clone.Equip.Text = "Unequipped"
                clone.Equipped.TextColor3 = Color3.fromRGB(247, 58, 58)
            end
        end
    end
    print("Got this line")
    newFrame.Equipped.Text = "Equipped"
    newFrame.Equip.Text = "Equipped"
    newFrame.Equipped.TextColor3 = Color3.fromRGB(105, 247, 98)
    game.ReplicatedStorage[folderName].EquippedPet.Value = newFrame.Name
end)

There are no errors. Nothing.

0
Try using ChildAdded to detect when people click the newframes laurenbtd5 379 — 4y
0
Thank you. I will try doing that and see if it works. Else, I will come back here and get back to you. Thank you! messi55313 -2 — 4y

Answer this question