Hello,
I’m making a pirate game and I am trying to make a “crew” system that will create a folder for crews in replicated storage and make a separate folder inside for each crew. What I am going for is to make it so the crew name is LocalPlayer.Name…" 's Crew ", any idea on how to go about this? This is my main script so far
local CreateCrewRE = game.ReplicatedStorage.RemoteEvents.CreateCrewRE
local CrewButton = game.ServerStorage.CrewButton.JoinCrewButton
local Crews = game.ReplicatedStorage.Crews
CreateCrewRE.OnServerEvent:Connect(function()
print("Crew created")
local Crew = Instance.new("Folder")
Crew.Parent = Crews
Crew.Name = "Player's Crew"
end)
1 Like
So on the server, there is no LocalPlayer, however, when you use the “OnServerEvent” signal, the connection returns an argument, the player!
So you can do this:
CreateCrewRE.OnServerEvent:Connect(function(player)
the code will result as:
local CreateCrewRE = game.ReplicatedStorage.RemoteEvents.CreateCrewRE
local CrewButton = game.ServerStorage.CrewButton.JoinCrewButton
local Crews = game.ReplicatedStorage.Crews
CreateCrewRE.OnServerEvent:Connect(function(player)
print("Crew created")
local Crew = Instance.new("Folder")
Crew.Parent = Crews
Crew.Name = player.Name.."'s Crew" -- ".." is used to concatenate (combine) two strings.
end)
3 Likes
Works great! I have one more question. There’s a “Crews” button that should show all the made crews but it’s not working… This is my server script now
local CreateCrewRE = game.ReplicatedStorage.RemoteEvents.CreateCrewRE
local CrewButton = game.ServerStorage.CrewButton.JoinCrewButton
local Crews = game.ReplicatedStorage.Crews
CreateCrewRE.OnServerEvent:Connect(function(player)
print("Crew created")
local Crew = Instance.new("Folder")
Crew.Parent = Crews
Crew.Name = player.Name.."'s Crew"
CrewButton:Clone()
CrewButton.Parent = game.StarterGui.MainMenu.CrewsFrame.CrewSelectionFrame
end)
Basically, you can’t just add it to StarterGui, it won’t update for them all, you will have to utilize the remote event, I’d suggest doing:
CreateCrewRE:FireAllClients(...)
Basically, you must send data to all the players saying that a crew was added and their individual clients can add the button to the UI.
1 Like
Thank you! But um, I’m not quite sure how to go about this… Do you think you could help me a bit?
You need a LocalScript in the MainMenu GUI that listens for CreateCrewRE.OnClientEvent, when it gets fired, the LocalScript makes a new “CrewButton”, the Server just uses
CreateCrewRE:FireAllClients(...)
1 Like
For example what sleep means is on the server do something like the following inside the same function on server (CreateCrewRE.OnServerEvent)
CreateCrewRE:FireAllClients(Crew.Name)
then create a localscript in starterGUI that listens to
CreateCrewRE.OnClientEvent
which is similar to what happens on the server, but instead works on the client. Inside your client function you can create a new button or something to fit your needs!
For more info I suggest reading about RemoteEvents on devhub
RemoteEvent
RemoteEvent.OnClientEvent
RemoteEvent.OnServerEvent