Server:
game.Players.PlayerAdded:Connect(function(player)
event:FireAllClients(player)
end)
local script:
event.OnServerEvent:Connect(function(player)
local newPlayer = player
end)
That’s how to transfer the data with a remote event.
Server:
game.Players.PlayerAdded:Connect(function(player)
event:FireAllClients(player)
end)
local script:
event.OnServerEvent:Connect(function(player)
local newPlayer = player
end)
That’s how to transfer the data with a remote event.
You can do something like this in a ServerScript:
local Remote = game.ReplicatedStorage["YOUR REMOTE NAME"]
game.Players.PlayerAdded:Connect(function(plr)
Remote:FireAllClients(plr)
end)
And that would send the player’s name to all clients. Then in a local script:
local Remote = game.ReplicatedStorage["YOUR REMOTE NAME"]
Remote.OnClientEvent:Connect(function(plr)
--Do stuff with the player's name with plr.Name
end)
DO NOT PASS THE PLAYER AS AN ARGUMENT ON THE CLIENT because roblox automatically provides that
I am pretty sure Roblox only automatically passes the name of the client firing the event if it is an event from a LocalScript to a ServerScript. The script I wrote out above was from server side to the client’s, how would it pass the client’s name over…?
I have no clue why it just does not work.
Server script:
local giveWeaponEvent = game.ReplicatedStorage.RemoteEvents:WaitForChild("GiveWeapon")
local assignTeamEvent = game.ReplicatedStorage.RemoteEvents:WaitForChild("AssignTeam")
local addFrameEvent = game.ReplicatedStorage.RemoteEvents:WaitForChild("AddFrame")
game.Players.PlayerAdded:Connect(function(plr)
addFrameEvent:FireAllClients(plr)
end)
Local script:
local mainFrame = script.Parent:WaitForChild("MainFrame")
local addFrameEvent = game.ReplicatedStorage.RemoteEvents:WaitForChild("AddFrame")
local sample = mainFrame:WaitForChild("Sample")
addFrameEvent.OnClientEvent:Connect(function(plr)
print(plr.Name.." has joined")
local clonedSample = sample:Clone()
clonedSample.Visible = true
clonedSample.Name = plr.Name
clonedSample.Text = plr.Name
clonedSample.Parent = mainFrame
print("Framed has been cloned")
end)
In game:
@InvalidArgvment Could you send us a screenshot of the Devconsole? The error might have been listed in there.
How to?
Could use F9;
/console;
/newconsole
Try that, F9 may not always work unless you use Shift+F9.
Do you mind opening the developer console and checking for any errors in the output? Also the RemoteEvents are stored in a folder named “RemoteEvents” correct?
Hmm, there are no visible errors. I have scripted something like this before a time ago, I can’t fully remember my code can’t look since I am on mobile.
Have you ensured that the label displaying the second player’s name has a different position than the first? It may just be hidden behind the first name if you haven’t done so.
Yup checked already, it also has an UI Grid layout in it.
I cannot think of any possible errors based on the scripts shown above, could I have a look at the object hierarchy please? It is the only thing I can think of causing errors right now, for example if a WaitForChild()
was used but the child didn’t exist. It wouldn’t produce an error, but the script would just be halted on the line.
sure but im currently rewriting my script. Here is what I have got so far: I’ve gotten an error in the output
local mainFrame = script.Parent:WaitForChild("MainFrame")
local addFrameEvent = game.ReplicatedStorage.RemoteEvents:WaitForChild("AddFrame")
local sample = mainFrame:WaitForChild("Sample")
while true do wait()
local playerService = game:GetService("Players")
for i, v in pairs(playerService:GetChildren()) do
if not mainFrame[v.Name] then
print("Player does not exist in the mainframe, add him.")
local clonedSample = sample:Clone()
clonedSample.Visible = true
clonedSample.Name = v.Name
clonedSample.Text = v.Name
clonedSample.Parent = mainFrame
print("Succesful")
else
print("Player already exist in the mainframe, dont add a frame")
end
end
end
error: InvalidArgvment is not a valid member of ScrollingFrame. I don’t understand this because Im using an IF statement, if it returns false it should return the else statement right??
Im trying to make a script that firstly checks if the frame of the player already exist in the gui, if not then add him so i dont have to use the table.remove() function which may cause the error.
That is correct. However I believe in this line:
if not mainFrame[v.Name] then
You are basically asking the system “If mainFrame.InvalidArgvment
is false, then do this.” However it does not exist in the first place, so it returns an error. You should try using:
if mainFrame:FindFirstChild(v.Name) then
print("Player already exist in the mainframe, dont add a frame")
else
print("Player does not exist in the mainframe, add him.")
local clonedSample = sample:Clone()
clonedSample.Visible = true
clonedSample.Name = v.Name
clonedSample.Text = v.Name
clonedSample.Parent = mainFrame
print("Succesful")
end
This would avoid the error.
Omg its working now, thank you so much!
Hello i had the same problem but this fixed it so the thing is when i will go in the game everything works but the gui collides like when i play 2 player test the player 1 gui and 2 collide is there a way i can separate these please help me
thanks in advanced
Update: fixed it with the Uilistlayout