What do you want to achieve? Keep it simple and clear!
I am trying to make a family system. Where the player can create or request to join families.
What is the issue? Include screenshots / videos if possible!
When you make the family it does not clone the sample button then change it’s name and text to the family name set by the player. let alone close down GUIs.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have checked the grid to check if it was visible and it was. I also checked that there weren’t any typos and there weren’t.
Here is my code;
it is a server script inside of serverscriptservice.
local RE1 = game.ReplicatedStorage.FamilyEvents.JoinFam
local RE2 = game.ReplicatedStorage.FamilyEvents.LeaveFam
local RE3 = game.ReplicatedStorage.FamilyEvents.CreateFam
local RE4 = game.ReplicatedStorage.FamilyEvents.DestroyFam
RE3.OnServerEvent:Connect(function(plr, FamName, plrId)
print(plrId)
print(FamName)
print("2")
local GUIs = plr.PlayerGui.FamilyGUI
local FamButton = GUIs.HasNoFam.Grid.Sample:Clone()
local NoFam = GUIs.HasNoFam
local Fam = GUIs.HasFam
FamButton.TextLabel.Text = FamName
FamButton.Visible = true
NoFam.Visible = false
Fam.Visible = true
Fam.TextLabel.Text = FamName.." Family"
if plr.UserId == plrId then
local Plr = Fam.Grid:FindFirstChild("Sample"):Clone()
print("3")
Plr.Visible = true
Plr.TextLabel.Text = plr.Name
Plr.Name = plr.Name
end
end)
My big tip is to not rely on Events to do things like that. Excluding it being exploitable, this could possible increase the ping between server → client. The exploiting part of this, exploiter would just have to type
destroyFamily:FireServer(someone else’s username Id etc…)
Oh wait, it appears I was wrong about the exploiting part. I didn’t see you stating the If Statement. But if you really need to send info from client → server I recommend passing through on one event a action parameter. Action: String, so all you would have to do is something like
RemoteEvent.OnServerEvent:Connect(function(plr, FamName, plrId, action: String)
if tostring(plr.UserID) == tostring(plrId) then print(plr,": possibly exploited!") return end;
if action == "destroy" then
elseif action == "create" then
elseif action == "leave" then
elseif aciton == "join" then
end
end)
The server can’t make changes to a player’s GUI properties. Only the client can. You need to put this code in a local script, and if you’re using a :FireServer() call anyway, you can just use the local script making said call and paste the code within this function over there.
Then, you can look into having listeners on all clients, and then using a :FireAllClients() call from the server. If you go this route, however, you need to make sure you verify the server request. Ideally, the server wouldn’t need to be told to make this change for all users by any client. But if that’s necessary, you need to make sure that client can’t spam. RemoteEvents can be called by bad actors (exploiters) at any time with any parameters. You need to be mindful of this.
If the GUIs need to change for everyone, you’ll need to call a :FireAllClients() call on a remote event, or if you want to fire it on multiple clients but not everyone (such as just the people in the specified family) you’ll need to loop through all those players and call the regular :FireClient() function.
Remote events should be placed in the ReplicatedStorage folder so that they can be accessed both by the client and the server. I usually make a folder called remotes in ReplicatedStorage for better organisation and then put all my remote events and functions in there.
To receive the event on the client, use a LocalScript somewhere where it will execute. For your purpose I suggest putting it in the StarterGUI folder, since it will be used for GUI purposes.
You can connect to the event fairly easily using RemoteEvent.OnClientEvent:Connect() where RemoteEvent is the Remote Event you put in the ReplicatedStorage.
I’m sure you know how to use event connections, but the function will also receive any arguments you gave the :FireClient() or :FireAllClients() call meaning you can give the client the data (name, family, playerID, etc).
Yeah, simpler terms. When you FireServer, on the server get the list of users within that family. Then, you would do something like
local family = {};
RemoteEvent.OnServerEvent:Connect(function(plr, FamName, plrId, action: String)
if tostring(plr.UserID) == tostring(plrId) then print(plr,": possibly exploited!") return end;
if action == "destroy" then
family[famName] = nil;
elseif action == "create" then
family[famName] = {player};
elseif action == "leave" then
local pos = table.find(family[famName], player);
if pos ~= nil then
table.remove(family[famName], pos);
end
elseif aciton == "join" then
table.insert(family[famName], player);
end
for i,v:Players in pairs(family[famName]) do
RemoteEvent:FireClient(v, "updateUI");
task.wait()
end
end)
Sorry if it’s indented wrong, I wrote this in devForum
When firing the server from the local script would it look like this?
--Outside of function
local RE = game.ReplicatedStorage.FamilyEvent
local FamName
local plrId = game.Players.LocalPlayer.UserId
local action
--Inside of function
action = "create"
RE:FireServer(FamName, plrId, action)