I am trying to make a tool datastore, and I made a folder to store all the values:
local myFolder = game:GetService("ReplicatedStorage").Folder:Clone()
myFolder.Parent = game.Players.LocalPlayer
myFolder.Name = game.Players.LocalPlayer.Name.."'s tools"
This is in a local script inside starter gui.
Now, I am trying to get the folder in a server script located in serverscriptservice
game.Players.PlayerRemoving:Connect(function(player)
local myFolder = player:WaitForChild(player.Name.."'s tools")
print(myFolder)
end)
It results to infinite yield, any idea how I can do this?
2 Likes
When the player leaves make it fire a remote event to the server with a table that has all the tool names then you can save that, your code doesn’t work because LocalScripts can’t see the contents of serverscriptservice
This is located in the local script, yes?
Yes make the client fire an event to the server
1 Like
to answer your question refer timo the documentation here:
1 Like
game.Players.PlayerRemoving:Connect(function()
local getToolsEvent = game:GetService("ReplicatedStorage").GetTools
local myTools = {myFolder:GetChildren().Value}
getToolsEvent:FireServer(myTools)
end)
The folder has string values that contains a value(name of the tool)
Actually nevermind I was being a bit silly, you should be able to see what tools are in the backpack from the server
Fire a remote event to the server referencing the foler and then set the folder as a parameter in the server
Oh it’s not like there is actually an inventory gui, whenever a player unlocks a tool I plan to put the value(name of the tool) to the server, then I plan of saving all the tools the player has before he/she leaves, no backpack stuff, it’s hard to explain
Job1.01 - Roblox check this game to see what I mean (touch the grey part for money)
I am not used to remote events, is this correct?
Local script:
local getToolsEvent = game:GetService("ReplicatedStorage").GetTools
game.Players.PlayerRemoving:Connect(function()
local myTools = {myFolder:FindFirstChildWhichIsA("StringValue")}
getToolsEvent:FireServer(myTools)
end)
Serverscript in ServerScriptService:
local getToolsEvent = game:GetService("ReplicatedStorage").GetTools
getToolsEvent.OnServerEvent:Connect(function(myFolder)
print(myFolder.Name)
end)