Sending a number formed from the client to the server

hey developers. i’ve been struggling with this issue for hours and its really got me beat.
im really bad at calling all this server/client stuff, so i really need some help.

my client script in my tool makes a makes a number in a numbervalue which is in a tool. however, my server script can’t access that number because it was made by the localplayer.

heres how the client looks:

local uis = game:GetService("UserInputService")

local mode = tool:FindFirstChild("Mode")
local power = tool:FindFirstChild("Power")
local function onInput(input, gameProcessed)
	if gameProcessed then return end

	if input.KeyCode == Enum.KeyCode.E then
		e4 = not e4
		mode.Value = e4 and "Shoot" or "Pass"
		print ("Mode Selected!")
	
if mode.Value == "Shoot" then
	power.Value = 125
elseif mode.Value == "Pass" then
	power.Value = 75
end
	end
	end

uis.InputBegan:Connect(onInput)

and heres my server script

		
			local direction = (mousePosition - ball.Position).Unit
			
				BV.Velocity = direction * MYNUMBERHERE -- instead of 125 i want it to be the value of the tool value

im really bad with this server and client transfer stuff, and i’ve been trying solutions for 3+ hours now. please help me.

1 Like

Could use a remote event to get it from client to server

1 Like

yes, i know you could do that, but the way my script is formatted im not exactly sure how i would make it, because you need a remoteEvent to transfer it, but my full situation looks like this

event.OnServerEvent:Connect(function(player2, action, ball, mousePosition)
	local mouse = player2:GetMouse()
	
	
	if action == "Throw" and ball:IsA("MeshPart") and ball.Name == "Ball" then
		thrown.Value = true
		
		print(player2.Name.. " is throwing the ball!")
		
		for _, child in ball:GetChildren() do
			if child:IsA("WeldConstraint") then
				child:Destroy()
		
	

		--end
		
		
			local BV = Instance.new("BodyVelocity", ball);
			BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			
			BV.Parent = ball
			
			local direction = (mousePosition - ball.Position).Unit
			
				BV.Velocity = direction * 125 (i want my number here, not 125)
		--ball.CFrame = CFrame.new(ball.Position)
		wait(.1)
			ball.BodyVelocity:Destroy()
		
		wait(2)
		
	
	
			end
		end
		
	end
	wait(1)
	thrown.Value = false
end)

my “throwing” system is already kind of on a remote event so im not sure how to do another one while already in one, if you know what i mean

can you send the other script so i can see

client (used to change powers and mode)

local e4 = false

local mode = tool:FindFirstChild("Mode")
local power = tool:FindFirstChild("Power")


local function onInput(input, gameProcessed)
	if gameProcessed then return end

	if input.KeyCode == Enum.KeyCode.E then
		e4 = not e4
		actionValue.Value = e4 and "Shoot" or "Pass"
		print ("Mode Selected!")

if mode.Value == "Shoot" then
	power.Value = 125
elseif mode.Value == "Pass" then
			power.Value = 75
end

	end
end
-- mobile

server (used for the velocity of throwing and throw physics)

event.OnServerEvent:Connect(function(player2, action, ball, mousePosition)
	local mouse = player2:GetMouse()
	
	
	if action == "Throw" and ball:IsA("MeshPart") and ball.Name == "Ball" then
		thrown.Value = true
		
		print(player2.Name.. " is throwing the ball!")
		
		for _, child in ball:GetChildren() do
			if child:IsA("WeldConstraint") then
				child:Destroy()
		
	

		--end
		
		
			local BV = Instance.new("BodyVelocity", ball);
			BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			
			BV.Parent = ball
			
			local direction = (mousePosition - ball.Position).Unit
			
				BV.Velocity = direction * 125
		--ball.CFrame = CFrame.new(ball.Position)
		wait(.1)
			ball.BodyVelocity:Destroy()
		
		wait(2)
		
	
	
			end
		end
		
	end
	wait(1)
	thrown.Value = false
end)

Oh, you could store the power value as a stat in the player so you can access it whenever

how would I do that exactly?

is that possible for the client to store and the server to receive?

You would also need to do a remote event but you make a stat in the player, then when the player selects the mode you fire a remote event which sends which mode they select or the power amount to a script that changes the stat

im not exactly sure how to write that out, guess i’ll keep looking for documentation

thanks for the assistance!

sorry i would write out an example but i am currently on a phone

If you are using a remoteEvent to sent those information anyways, why not just add an argument and send the power.Value on the client. power.Value is a number, not an instance, so the server should be able to access it.

well his local script he sent isn’t firing it so he can’t just add the value

From my understanding, you want the tool to set the power of the player’s basketball shot right? You could just use the same function you already have for the E key to fire the events from there to the server which sets a stat somewhere both the client and server can see like the Player instance.

For example:

if mode.Value == "Shoot" then
	powerChangeEvent:FireServer(125) -- fire to server with a value of 125
elseif mode.Value == "Pass" then
	powerChangeEvent:FireServer(75) -- fire to server with a value of 75
end

This is assuming you have a stat saved somewhere for this script. You can easily just add it somewhere whenever the character is loaded for states and what not.

powerChangeEvent.OnServerEvent:Connect(player,Val)
	local powerVal = player.BallPower.Value
    powerVal = Val 
end)
1 Like

This is very helpful. Instead of putting the value in the tool, I gave it to the player.

However, i’m a little confusing with the firing stuff. Because my event already does quite a bit:

event.OnServerEvent:Connect(function(player, action, ball, mousePosition, val)

so how do we specify that the number we fired is supposed to be the val?

could you be a little bit more specific on what you are trying to do? is it what is shown above by chilly?

You would put the value behind the parameter mousePosition.

So, your remote event should look something like (based on your current parameters)

event:FireServer("Throw", ballObject, mouseP, player.BallPower.Value)

Since the power value is saved in the player, both the server and client can see it. You can refer to the power value saved in the player as the val parameter.