Table Values Arent Sent To ClientScript/LocalScript

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    for it to print the strings and then do stuff from there
  2. What is the issue? Include screenshots / videos if possible!
    FireClient doesnt send the strings?
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Havent found any, and i dont think i will since im a beginner at this stuff
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- OnServerScript
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")

DataSender1 = ReplicatedStorage:WaitForChild("DataSender1")

ServerModule = require(ServerScriptService:WaitForChild("ServerModule"))

ActionTable = {"Action1", "Action2"}

DataSender1.OnServerEvent:Connect(function(Player, Data, Action)
	if Action == "Action1" then
		ServerModule.IncreaseLeaderStats(Player, Data, Action)
	end
	if Action == "Action2" then
		ServerModule.CreatePlayersCode(Player, Data, Action)
	end
	if Action == "Action3" then
		DataSender1:FireClient(Player,ActionTable)
	end
end)
-- OnClientScript
Interface = script.Parent

Player = game:GetService("Players").LocalPlayer
ReplicatedStorage = game:GetService("ReplicatedStorage")

CodeBox = Interface:WaitForChild("TextBox")
ClickButton = Interface:WaitForChild("Clicker1")

LeaderStats = Player:WaitForChild("leaderstats")

DataSender1 = ReplicatedStorage:WaitForChild("DataSender1")

ClickButton.MouseButton1Click:Connect(function()
	DataSender1:FireServer(LeaderStats, "Action1")
end)

CodeBox.FocusLost:Connect(function(Entered)
	if Entered then
		DataSender1:FireServer(CodeBox.Text, "Action2")
	end
end)

DataSender1:FireServer(Player,"Action3")

DataSender1.OnClientEvent:Connect(function(Player, Table)
	print(Table[1], Table[2])
	print("Works if it prints", Table)
end)

If i pasted this out correctly, you should see the full code

OnClientEvent only returns the Variables after Player.

DataSender1.OnClientEvent:Connect(function(Table)
	print(Table[1], Table[2])
	print("Works if it prints", Table)
end)

Im confused, i thought onclientevent, you put the player first and then the parameters that were sent from fireclient? and i also tried removing player from FireClient and then got an error

Nope, the client only received it because the Server sent it to it. No need to give it the player as it’d just be the same as LocalPlayer.

This would be the same for sending data from the Client to the Server. You did :FireServer(Player,“Action3”) but the server already knows where the request came from so it’ll automatically add Player as a variable. Which means yours would actually return (Player,Player,“Action3”)

-- Client Script
Example:FireServer("Hi")

-- Server Script
Example:OnServerEvent:Connect(function(Player,Variable)
    print(Player,Variable)
end)
-- Server Script
Example:FireClient(Player,"Hi")

-- Client Script
Example:OnClientEvent:Connect(function(Variable)
    print(Variable)
end)

oh, so i removed Player argument and it worked, thank you for correcting me on that :), also had to change a few things and it started to work

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.