Ok, so I am trying to make this LOCAL script send a gui’s name, and whenever it is clicked I fire the remote event and send the GUI that was clicked and its name, but for some reason it is treating it like a player. I am using a for loop to go through every GUI in this frame and say whenever it is clicked I fire the event and send the GUI and player like I said. Its just replacing the GUI with the player.
This is the local script that sends the signal
local ThunderClanSpawnButton = script.Parent:WaitForChild("ThunderClanSpawn")
local FlagPointSpawn = script.Parent:WaitForChild("FlagPointSpawn")
local ShadowClanSpawnButton = script.Parent:WaitForChild("ShadowClanSpawn")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpawnEvent = ReplicatedStorage:WaitForChild("SpawnEvent")
local Frame = script.Parent
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
for i,v in pairs(Frame:GetChildren()) do
if v.ClassName == "TextButton" then
v.Activated:Connect(function(player, v)
SpawnEvent:FireServer(Player,v)
end)
end
end
and this is the script that RECEIVES the signal, ignore the give weapon function. Also the output only prints my player name 2 times, 0 and it was sent.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpawnEvent = ReplicatedStorage:FindFirstChild("SpawnEvent")
SpawnEvent.OnServerEvent:Connect(function(player, TeamRequest)
print("it was sent")
print(player)
print(TeamRequest)
if TeamRequest.Name == "ThunderClanSpawn" and player.Team.Name == "ThunderClan" then
print("YE ON THUNDER")
elseif TeamRequest.Name == "ShadowClanSpawn" and player.Team.Name == "ShadowClan" then
print("YE ON SHADOW")
elseif TeamRequest.Name == "FlagPointSpawn" then
local FlagPoint = game.Workspace.BattleField:WaitForChild("FlagCapture")
if FlagPoint.CaptureColor.Value.Name == "Dark stone grey" then
print("THUNDER CLAN OWNS THE FLAG!!!")
elseif FlagPoint.CaptureColor.Value.Name == "Black" then
print("SHADOW CLAN OWNS MIDDLE")
else
print("Something is wrong with the code :(")
end
end
end)
local function GivePlayerWeapon(Person)
if Person.Team.Name == "ThunderClan" then
local Weapons = game.ServerStorage:FindFirstChild("Weapons").ThunderClan:GetChildren()
local RandomWeapon = Weapons[math.random(1,#Weapons)]
local GunClone = RandomWeapon:Clone()
GunClone.Parent = Person.Backpack
elseif Person.Team.Name == "ShadowClan" then
local Weapons = game.ServerStorage:FindFirstChild("Weapons").ShadowClan:GetChildren()
local RandomWeapon = Weapons[math.random(1,#Weapons)]
local GunClone = RandomWeapon:Clone()
GunClone.Parent = Person.Backpack
end
end
When firing a RemoteEvent from the LOCAL script. You do not need to pass in a Player as an argument.
If you will need the player in the server, so that you are able to tell which player clicked the GUI. Whenever OnServerEvent() triggers, the first parameter is default as the Player.
So in your for loop from your local script, you do not need to pass in the player as an argument when firing the server.
for i,v in pairs(Frame:GetChildren()) do
if v.ClassName == "TextButton" then
v.Activated:Connect(function(player, v)
SpawnEvent:FireServer(v)
end)
end
end
It is sending the player twice, because in the local script, you are doing SpawnEvent:FireServer(Player,v). When the server receives the remote, the first parameter is already the player, that means that you can just do this:
so I tested it and what you said was true, but then for the parameter for the GUI the player clicked, it just says nil. Is my for loop incorrect or do I need to replace “V” with something. In case you are wondering here is the server script that is RECIEVING the event.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpawnEvent = ReplicatedStorage:FindFirstChild("SpawnEvent")
SpawnEvent.OnServerEvent:Connect(function(player, TeamRequest)
print("it was sent")
print(player)
print(TeamRequest)
if TeamRequest.Name == "ThunderClanSpawn" and player.Team.Name == "ThunderClan" then
print("YE ON THUNDER")
elseif TeamRequest.Name == "ShadowClanSpawn" and player.Team.Name == "ShadowClan" then
print("YE ON SHADOW")
elseif TeamRequest.Name == "FlagPointSpawn" then
local FlagPoint = game.Workspace.BattleField:WaitForChild("FlagCapture")
if FlagPoint.CaptureColor.Value.Name == "Dark stone grey" then
print("THUNDER CLAN OWNS THE FLAG!!!")
elseif FlagPoint.CaptureColor.Value.Name == "Black" then
print("SHADOW CLAN OWNS MIDDLE")
else
print("Something is wrong with the code :(")
end
end
end)
local function GivePlayerWeapon(Person)
if Person.Team.Name == "ThunderClan" then
local Weapons = game.ServerStorage:FindFirstChild("Weapons").ThunderClan:GetChildren()
local RandomWeapon = Weapons[math.random(1,#Weapons)]
local GunClone = RandomWeapon:Clone()
GunClone.Parent = Person.Backpack
elseif Person.Team.Name == "ShadowClan" then
local Weapons = game.ServerStorage:FindFirstChild("Weapons").ShadowClan:GetChildren()
local RandomWeapon = Weapons[math.random(1,#Weapons)]
local GunClone = RandomWeapon:Clone()
GunClone.Parent = Person.Backpack
end
end
It is basically saying that there is no such thing as TeamRequest(team request is the GUI the player clicked)
This is the for loop in your local script, correct?
for i,v in pairs(Frame:GetChildren()) do
if v.ClassName == "TextButton" then
v.Activated:Connect(function(player, v)
SpawnEvent:FireServer(v)
end)
end
end
If so, try removing the second parameter (v) from the 3rd line of the for loop of the code I sent. See if it makes any difference.
So it should be something like:
for i,v in pairs(Frame:GetChildren()) do
if v.ClassName == "TextButton" then
v.Activated:Connect(function(player)
SpawnEvent:FireServer(v)
end)
end
end
Thank you so much! So did my script now work because I was using v in the function in which the function made v the player. So then by changing it I am not changing what v is, because in the for loop it was the GUI the player clicked, but the function made it the player. Am I correct on how I was wrong?(sorry for my bad grammar)
To make things clear, the v you’re passing in your arguments when firing the server from a local script, is the GUI.
Meanwhile in the server, when it receives OnServerEvent(), the first parameter will always be the player or client that fired the remote event (by default). The second parameter will be the GUI, which is the v that was passed in, inside your local script’s fire event function.