Can this code be better?

So Basically I’m Trying to get the players y position to 0,
So I move the baseplate to a y position where when the player stands on the baseplate it’s 0

I want to know if theres more ways to script this instead of just moving the baseplate to the axis where the player y is 0.

Script:

local Runservice = game:GetService("RunService")

Runservice.RenderStepped:Connect(function()
	print(math.floor(game.Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart").Position.y))
end)
1 Like

This looks good but you could also do:

local runService = game:GetService(“RunService”)

local function doDomething()
print(math.floor(game.Players.LocalPlayer.Character:FindFirstChild(“HumanoidRootPart”).Position.y))
end)

runService.RenderStepped:Connect(doSomething)

1 Like

Oh but why do that though? wouldn’t they do the same?

1 Like

yes its just more organized, The functions and the variables at the top, and the code that’s gonna run under them.

2 Likes
local RunService = game:GetService("RunService")

RunService.RenderStepped:Connect(function()
	print(math.round(game.Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart").Position.Y))
end)

There’s a difference to this though, because I believe math.round() rounds to the nearest whole number (example, math.round(0.6) returns 1), math.floor() rounds to the nearest integer below its current number (example, math.floor(1.7) returns 1).

you can multiply the players position by Vector3.new(1,0,1) and the y is multiplied by 0 so it is set to 0
for renderstepped I would recommend BindToRenderStep as It has priorities (1 being ran first 2 being ran next)