-- on client
remoteEvent:FireServer(textBox.Text) -- send to server
-- on server
local textPerPlayer = {}
remoteEvent.OnServerEvent:Connect(function(player, text)
textPerPlayer[player] = text
end)
--somewhere else on server
local text = textPerPlayer[player] -- fetch text
I see, here’s the modified script:
Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local numberService = ReplicatedStorage:WaitForChild("LotteryNumberService")
local LotteryCard = game:GetService("Lighting").LotteryCard -- this line is for later don't bother with it
local sendNumbertoServer = Instance.new("RemoteEvent")
sendNumbertoServer.Parent = ReplicatedStorage
sendNumbertoServer.Name = "LotteryNumberService"
local NumberMap = {}
local function onButtonPress(text)
local playerNumber = tonumber(text)
if playerNumber and playerNumber >= 0 and playerNumber <= 100 then
NumberMap[player] = playerNumber
end
end
sendNumbertoServer.OnServerEvent:Connect(function(player, text)
onButtonPress(text)
end)
Local Script
local TextButton3 = script.Parent
local Players = game:GetService("Players").LocalPlayer.PlayerGui
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GetNumberService = ReplicatedStorage:WaitForChild("LotteryNumberService")
local TextBox = Players.ChatBox1.Frame.TextBox
TextBox:GetPropertyChangedSignal("Text"):Connect(function()
TextBox.Text = TextBox.Text:gsub('%D+', '');
TextBox.Text = TextBox.Text:sub(1,3);
end)
script.Parent.MouseButton1Click:Connect(function()
GetNumberService:FireServer(TextBox.Text)
end)
I did the number conversion from the server cuz strings are less expensive to send compared to 64 bit numbers
Shouldn’t the user see the input as numbers only? Let’s say the input is like hell018o
, it should only appear as 018
in the textbox and not hell018o
Thank you everyone for your help. How would I know that the server received the number? Can I just print the text variable out or is that not possible? Do I have to make a seperate script fetching the number?
On the server you can just print playerNumber
The event sends the number? So you know its recieved?
I guess I am tripping. Thought that:
Was on the Server-Code you posted because of:
Huh. Guess it just still doesn’t work. Doesn’t throw any errors at me or anything either.
where’d you get the player in NumberMap?
If you add prints, what does the output show?
You need to add a new param to that it’s wrong
local function onButtonPress(text, player)
onButtonPress(text, player)
Huh? I’m adding a new element in the dictionary. So that whenever you wanna get the number the player sent when creating a note, you can just do NumberMap[player]
. Also NumberMap is declared above the function somewhere
Nothing. I’ve tried adding prints to every server script I’ve been given in this thread.
Oh, okay. It’s just that it showed up as an unknown global.
So not even right after:
I think you should create the RemoteEvent by yourself instead of script
Problem is player is not defined anywhere.
What do you mean? The first parameter on OnServerEvent
is always player