I made a i v in pairs loop to find anything that is a textbutton, then after that I fire a remote event.
On the server script I’m trying to make it check which button was activated.
I’m not sure what is going on, nothing is printing in the out put.
Client Script:
local repstorage = game:GetService("ReplicatedStorage")
for index, value in pairs(script.Parent.Parent.Parent.ShopFrame.TrailFolder:GetChildren()) do
if value:IsA("TextButton") then
value.MouseButton1Click:Connect(function(SelectedButton)
repstorage.RemoteEvent:FireServer(SelectedButton)
end)
end
end
Server Script:
local repstorage = game:GetService("ReplicatedStorage")
local button = game.StarterGui.Shop.ShopFrame.TrailFolder
repstorage.RemoteEvent.OnServerEvent:Connect(function(SelectedButton)
if SelectedButton == button.Trail1 then
print("P1")
if SelectedButton == button.Trail1 then
print("P2")
end
end
end)
The SelectedButton exists only on the client—as do all items within your GUI—so the server receives nil. You could try naming each button what you want and then sending through the name.
Alright so, I did some testing and it works, I also change the name of the remote event also. But when I use if statements nothing happens.
Also if didn’t mention the player it wouldn’t work for some weird reason
local repstorage = game:GetService("ReplicatedStorage")
local button = game.StarterGui.Shop.ShopFrame.TrailFolder
repstorage.TrailRemote.OnServerEvent:Connect(function(player, value)
if value == button.Trail1 then
print("p1")
if value == button.Trail2 then
print("p2")
end
end
end)
I just noticed an issue in your previous scrpt. The second if statement is inside the first one, which won’t work. Maybe try this?
--CLIENT
local repstorage = game:GetService("ReplicatedStorage")
for index, value in pairs(script.Parent.Parent.Parent.ShopFrame.TrailFolder:GetChildren()) do
if value:IsA("TextButton") then
value.MouseButton1Click:Connect(function()
repstorage.RemoteEvent:FireServer(value.Name)
end)
end
end
--SERVER
local repstorage = game:GetService("ReplicatedStorage")
local button = game.StarterGui.Shop.ShopFrame.TrailFolder
repstorage.RemoteEvent.OnServerEvent:Connect(function(Player, SelectedButton)
if button[SelectedButton].Name == "Trail1" then
print("P1")
elseif button[SelectedButton].Name == "Trail2" then
print("P2")
end
end)
You could alternatively use :WaitForChild(SelectedButton) or :FindFirstChild(SelectedButton). SelectedButton is essentially a name you’re passing through the remote. If you were to type button.SelectedButton it would error because SelectedButton isn’t a child of the TrailFolder. You’re trying to see if the name you’re passing through the remote matches with ACTUAL children in the trail folder.