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.
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
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)
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
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.
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)
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.