Faczki
(Faczki)
July 27, 2021, 11:07pm
#1
Basically i am making a script to create a folder with a player’s name when they join the game and delete it when they leave.
I’m just having some trouble at the deleting part, this is my script so far:
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder", workspace.Horses)
folder.Name = plr.Name
end)
game.Players.PlayerRemoving:Connect(function(plr)
game.Workspace.Horses:FindFirstChild(plr.Name):Destroy()
end)
Note: “Horses” is a folder in workspace.
The creating part will work just fine but i’m just not sure if the removing part will work (as i can’t check because i would’ve left the game).
So if someone could tell me if this would work or another way to do it i would very much appreciate it, thanks.
1 Like
Hazgani
(Pagani)
July 27, 2021, 11:10pm
#2
You can test this by starting up a local server with 2 players. Leave with one of the 2 clients and check workspace.Horses. If the folder is deleted then your script works. I don’t see anything wrong with your script here.
Faczki
(Faczki)
July 27, 2021, 11:11pm
#3
How would i start a local server with 2 players inside studio?
Hazgani
(Pagani)
July 27, 2021, 11:12pm
#4
Go on the test tab and there should be a button with a screen on it, if I’m not mistaken.
Hazgani
(Pagani)
July 27, 2021, 11:17pm
#6
It explains the steps very well on this website: https://developer.roblox.com/en-us/articles/game-testing
Scroll down to multi client simulation
Abcreator
(Abcreator)
July 27, 2021, 11:25pm
#7
You should not be using the second argument of Instance.new
I’ve discovered a pretty bad performance issue in one of top games that has to do with Instance.new and wanted to write about this, since this is not obvious unless you know the system inside out.
Tthere are several ways to create a ROBLOX object in Lua:
local obj = Instance.new(‘type’); fill obj fields
local obj = Instance.new(‘type’, parent); fill obj fields
local obj = util.Create(‘type’, { field1 = value1, … })
If you care at all about performance, please only use the first option - I wi…
1 Like
Rami_XD1
(RamiDeV)
July 27, 2021, 11:49pm
#8
Go to the Test menu and check it with two or more players as you want and see what will happen in the workspace
yeah this will work
Airzy_Az
(air)
July 28, 2021, 12:00am
#9
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder", workspace.Horses)
folder.Name = plr.Name
game.Players.PlayerRemoving:Connect(function(plr2)
if plr == plr2 then
folder:Destroy()
end
end)
end)
1 Like