Issue with sending client data to server side

As much as I am a newbie and I am just learning scripting I have been looking for a solution to this issue but I could not find the solution anywhere, so I am asking for help here

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local buttonClickEvent = ReplicatedStorage:WaitForChild("TextButton")
if buttonClickEvent then
	local button = script.Parent
	button.MouseButton1Click:Connect(function()
		local player = game.Players:GetPlayerFromCharacter(button.Parent)
		local value = math.random(1, 5)
		buttonClickEvent:FireServer(player, value)--value never displayed on server side!!!!!
	end)
end

^ this is my script example ^ in this script I try to send value and player name to the server side

local buttonClickEvent = Instance.new("RemoteEvent")
buttonClickEvent.Name = "TextButton"
buttonClickEvent.Parent = game.ReplicatedStorage
buttonClickEvent.OnServerEvent:Connect(function(player,value)
	print(player,value)-- Always only prints Player name and nil :(
end)

^ this is the server side script that is supposed to print the player name and value but it only prints player name and “nil”

I don’t know how to fix this, I wasted too much time on this simple seeming issue

Don’t pass the player parameter client-side - it is automatically passed.

buttonClickEvent:FireServer(value)

buttonClickEvent.OnServerEvent:Connect(function(player, value)

Should work.

Also, I’d recommend making the RemoteEvent outside of the playing. Just add a RemoteEvent to RepicatedStorage and call it whatever name you use. Then:

Client:

local rStorage = game:GetService("ReplicatedStorage")
local buttonClickEvent = rStorage:WaitForChild("TextButton")

Server:

local rStorage = game:GetService("ReplicatedStorage")
local buttonClickEvent = rStorage.TextButton
3 Likes

thank you so much!
I am just a beginner at studio stuff and new to the dev forums
do you have anything you can recommend me to learn scripting quicker? For now I am just typing random nonsence and making a game out of it

1 Like

Sorry, I’m self-taught so all I can recommend is just experimenting with stuff you know…

1 Like

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