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

Script only executes properly once?

Asked by 5 years ago
Y = 0
local ds = game:GetService("DataStoreService"):GetDataStore("ToolSt6yy67yyyyqadryyyaayyyyyyyyyyyve") 
game.Players.PlayerAdded:connect(function(plr)
inventoryGUI = game.ReplicatedStorage.Inventory:Clone()
inventoryGUI.Parent = plr.PlayerGui
lol = Instance.new("Folder", plr)
lol.Name = "leaderstats"
lol.Parent = plr
     pcall(function() 
        local tools = ds:GetAsync(plr.UserId) 
        print(tools)
        if tools then 
            for i,v in pairs(tools) do 
                local tool = game.ReplicatedStorage.Values:FindFirstChild(v)
                 if tool then 
                    plr:WaitForChild("leaderstats")
                    tool:Clone().Parent = plr.leaderstats
                    print(tool)
                    wait()
                    Text  = Instance.new("TextLabel")
                    Text.TextSize = 30
                    Text.TextColor3 = Color3.new(255, 0, 0)
                    Y = Y + 0.2
                    Text.Text = tool.Name
                    Text.Parent = plr.PlayerGui.Inventory.Frame
                    Text.Position = UDim2.new(0.5, 0, Y, 0)

                end 
            end 
        end
     end)
 end)
 game.Players.PlayerRemoving:connect(function(plr)
    toolsToSave = { }
     pcall(function() 
         for i,v in pairs(plr.leaderstats:GetChildren()) do 
            if v then 
                table.insert(toolsToSave,v.Name) 
                print(v.Name)
            end 
        end 
        ds:SetAsync(plr.UserId,toolsToSave) 
    end) 
end)


game.ReplicatedStorage.AwardItem.OnServerEvent:connect(function(player, Item)
    print(player)
    print(Item)
    PlayerName = player
    ItemNew = Instance.new("IntValue")
        ItemNew.Name = Item
    ItemNew.Parent = game.Players[player.Name].leaderstats

end)




The problem is, when someone joins the game, it loads everything properly. But the next person that joins does not get the text of what skins they have. That means only the first peroson can see it properly. How would I fix this?

0
You can't access the PlayerGui from the server. Also, connect is deprecated switch to Connect. The parent argument to instance.new is also deprecated. It's known to cause latency. User#19524 175 — 5y
0
Can I use an remote event to fire the items names to a local script? Thepoint13 99 — 5y
0
Incapaz, that's wrong, you can access it, even find childs in it, however, like any normal thing, anything created by the client is client only, anything created by the server is visible to both, unless changed by the client User#20388 0 — 5y

Answer this question