Help with RemoteEvents

How do I get a value from a local script that I used to fire a Remote event?

Local Script:

local TextBox = script.Parent
local Event = game.ReplicatedStorage.LivesEvent

TextBox.FocusLost:Connect(function()
local TextBoxText = TextBox.Text

Event:FireServer(tonumber(TextBoxText))

print("Lives set to: "..TextBoxText)

end)

Server Script:

local Event = game.ReplicatedStorage.LivesEvent
local Lives = game.ReplicatedStorage.Lives

Event.OnServerEvent:Connect(function()

end)

https://gyazo.com/5fe2a4793f99bced2058d128aba27931

I want the server script to change the value of an IntValue object ( to the value that was entered on the textbox in which the local script is located.

Put it in your arguments:

Event.OnServerEvent:Connect(function(client, text)

The client is there because roblox implicitly passes a reference to the player who fired the event. So from there you can do whatever you want to the player if you need to

1 Like

How do I use that to change the value of the IntValue object?

Server Script:

local Event = game.ReplicatedStorage.LivesEvent
local Lives = game.ReplicatedStorage.Lives

Event.OnServerEvent:Connect(function(client, text)
if type(text) ~= “number” then
Lives.Value = text --Idk :sweat_smile:
end)

well sir, simply put you added a ~ were it wasn’t needed you want the type of text to == “number” being you’re already casting it to a number, that and ur missing an end

In your code, the ~= checks if not equals. You would want to change it to == to check if text is a number.

local Event = game.ReplicatedStorage.LivesEvent
local Lives = game.ReplicatedStorage.Lives

Event.OnServerEvent:Connect(function(client, text)
	if type(text) == "number" then
		Lives.Value = text
	end
end)