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

I tried to do a forum but when i post it duplicates [repost] ?

Asked by 5 years ago

Hello, i am trying to do a forums GUI with datastores, but the problem is that when i post it duplicates, an example

if the message 1 is a and the message 2 is b i will get a b b and if the message 3 is c i will get a c c c It overwrites the other messages and duplicates, why ?

function newp(info)

        local a = script.Parent.pos:Clone()

        a.Name = info.realName
        a.Parent = script.Parent.psts
        a.Visible = true
    local success, image, ready = pcall(function()
    return game.Players:GetUserThumbnailAsync(info.usid, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420) 
    end)
    if success then
            if ready then
    a.im.Image = image
            end

    end
    local elaboratedUD = UDim2.new(0,0,0,script.Parent.psts.UIListLayout.AbsoluteContentSize.Y)
    script.Parent.psts.CanvasSize = elaboratedUD
a.des.Text = info.Text
a.us.Text = info.Name
if info.Name == "maumaumaumaumaumau" then
    a.OW.Visible = true

end

if info.usid == script.Parent.Parent.Parent.Parent.UserId then
    a.del.Visible = true
    a.del.MouseButton1Click:Connect(function()
        a:Destroy()
        print("clicked")
    local dtstore = game:GetService("DataStoreService"):GetDataStore("adatastore")
            local ps = dtstore:GetAsync("Posts")

            for i,v in pairs(ps) do
                if v == info.id then
                    print("found")
                    table.remove(ps,i)
                end
            end -- remove the post from table if the delete button was clicked
            dtstore:SetAsync(info.realName,false)
            dtstore:SetAsync("Posts",ps)
            loadData()
    end)

end
if script.Parent.Parent.Parent.Parent.Name == "maumaumaumaumaumau" then
    if a.del.Visible == false then
    a.del.Visible = true
-- for me
    a.del.MouseButton1Click:Connect(function()
        a:Destroy()
    local dtstore = game:GetService("DataStoreService"):GetDataStore("adatastore")
            local ps = dtstore:GetAsync("Posts")

            for i,v in pairs(ps) do
                if v == info.id then
                    table.remove(ps,i)
                end
            end -- delete the post from the table posts
            dtstore:SetAsync(info.realName,false)
            dtstore:SetAsync("Posts",ps)
            loadData()
    end)
end
end
end

    function loadData()
    local dtstore = game:GetService("DataStoreService"):GetDataStore("adatastore")
    local ps = dtstore:GetAsync("Posts")
    for i,v in pairs(script.Parent.psts:GetChildren()) do
        if v:IsA("Frame") then
            v:Destroy()
        end
    end
    if not ps then

        dtstore:SetAsync("Posts",{})
        ps = dtstore:GetAsync("Posts")
    end

    for i,v in pairs(ps) do
        local dt = dtstore:GetAsync("P-"..v)
        if dt ~= false then
        newp(dt)
        end
    end
    end

    loadData()

    script.Parent.send.OnServerEvent:Connect(function(plr,txt)

        local dtstore = game:GetService("DataStoreService"):GetDataStore("adatastore")
            local ps = dtstore:GetAsync("Posts")
            local nm = 0
            for i,v in pairs(ps) do
                if not ps[tostring(tonumber(v)+1)] then
                    nm = tonumber(v)+1 -- make a new number
                    break
                end
            end
            if nm == 0 then
                nm = 1
            end
            table.insert(ps, tostring(nm))
            dtstore:SetAsync("Posts", ps)
            dtstore:SetAsync("P-"..tostring(nm), {
                realName = "P-"..tostring(nm),
                usid = plr.UserId,
                Name = plr.Name,
                Text = txt,
                id = tostring(nm)
                }) -- set the table data

            loadData() -- reload the data


    end)

Answer this question