I have this function that asks the server what a player’s walkspeed is. It’s receiving the walkspeed fine, as it is printing the right thing. The problem is, I’m having it return the speed, but when I call the function, it’s not showing anything.
local function WalkSpeedAsk()
Network.Remotes.Events.WalkSpeedAsk:FireServer()
Network.Remotes.Events.WalkSpeedAsk.OnClientEvent:Connect(function(Speed)
print("walkspeed: "..tostring(Speed))
return Speed
end)
end
it will just print function blablalbalbalba
try this:
local function WalkSpeedAsk(Func)
Network.Remotes.Events.WalkSpeedAsk:FireServer()
Network.Remotes.Events.WalkSpeedAsk.OnClientEvent:Connect(function(Speed)
print("walkspeed: "..tostring(Speed))
Func(Speed)
end)
end
You cannot return a value like this. The value will only be returned to the environment that calls the OnClientEvent connection (The C++ Roblox Environment). Return statements do not traverse through stacks like this.
Your code should look like this:
local function WalkSpeedAsk()
Network.Remotes.Events.WalkSpeedAsk:FireServer()
return Network.Remotes.Events.WalkSpeedAsk.OnClientEvent:Wait()
end
RBXScriptSignal:Wait() waits for the event to fire and returns the arguments passed to the signal. The updated code returns the walkspeed that was passed to the remote.
Actually, looking at this, you should be utilizing RemoteFunctions since they’re designed to do exactly what you want:
-- Client side
local function WalkSpeedAsk()
-- Returns the value that was returned from the server
return Network.Remotes.Events.WalkSpeedAsk:InvokeServer()
end
-- Server side
-- Connect to callback the RemoteFunction
RemoteFunction.OnServerInvoke = function(player)
--Get the player's WalkSpeed
return WalkSpeed -- return the player's WalkSpeed
end
local function WalkSpeedAsk(): number
local remote = Network.Remotes.Events.WalkSpeedAsk
remote:FireServer()
return remote.OnClientEvent:Wait()
end
local speed = WalkSpeedAsk()
print("WalkSpeed: "..speed)
Is this for a speed hacker check?
Guess I don’t get the point of this from a local script …
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humaniod = char:WaitForChild("Humanoid")
local speed = humaniod.WalkSpeed
print(speed)
I did create a secure speed hack test for you if that’s it.
The return Speed is in the scope of the function passed to Network.Remotes.Events.WalkSpeedAsk.OnClientEvent, if you return a value it will be returned there and not in the actual function “WalkSpeedAsk”, if you want to return the speed, do this:
local function WalkSpeedAsk()
Network.Remotes.Events.WalkSpeedAsk:FireServer()
local speed = Network.Remotes.Events.WalkSpeedAsk.OnClientEvent:Wait()
print("walkspeed: "..tostring(Speed))
return Speed
end