How can i transfer this data to a server script?

Hello, I am trying to make a terrain generation game for fun I have a gui where you can set a number press a generate button that will connect to a remote event that will then enable the terrain generation the problem is I need to set a value in the rep storage to be the number of whatever the person inputted then the terrain gen script will see it but I cant do this in the local script because the terrain script is a server. So how can i parse through the integer to the event script that will enable the terrain?

heres my code for my my gui button

--//Locals

local event = game.ReplicatedStorage.Events.TerrainGeneration
local tweenService = game:GetService("TweenService")
local tweenInformation = TweenInfo.new(2)
local p = {TextTransparency = 1}
local d = false

--//Main

script.Parent.MouseButton1Up:Connect(function()
if not d then
	d = true
	script.Parent.c:Play()
	
	local terrainGenerationNumber = tonumber(script.Parent.Parent.Number.Text)
	if terrainGenerationNumber then
		
		print("Success: Starting Terrain Generation")
		event:FireServer()
		script.Parent.Parent.Enabled = false
		
	else
		
		print("Error: Invalid Number")
		script.Parent.Parent.invalid.TextTransparency = 0
		wait(1)
		local tween = tweenService:Create(script.Parent.Parent.invalid, tweenInformation, p)
		tween:Play()
		
	end
	
	d= false
end
end)

heres my code for my event handler

--//Locals

local event = game.ReplicatedStorage.Events.TerrainGeneration

--//Main

game.Players.PlayerAdded:Connect(function(player)

event.OnServerEvent:Connect(function()
	
	print("Running Terrain Generation")
	local char = player.Character
	local int = player.PlayerGui.TerrainGenerator.Number.Text
	wait(1)
	game.ReplicatedStorage.Values.BASE_HEIGHT.Value = int
	char.HumanoidRootPart.Anchored = false
	game.ServerScriptService.TerrainBlockGenerationChunkLoading.Disabled = false
	
end)

end)

if you can help me this would be amazing!

This article can help you; Bindable Events and Functions | Roblox Creator Documentation

i don’t know if you know this or i just couldn’t understand the question but you can send extra information with remote events so i would say whatever integer you want to send do this,

from local script

event:FireServer(theIntValue)

to server script

event.OnServerEvent:Connect(function(plr, theIntValue)
        --other code!
end)

btw player parameter is needed or you might get confused for half an hour.

2 Likes

Ahh thanks this is what im trying to do but I dont quite understand it I didnt know you had to pass the player first then the thing your trying to pass

1 Like