I am trying to make a fly command but I do not know how to code it in the script if you would tell me please try and explain it in as much detail as you can please. I really hope I can make it to finish my admin commands.
commands.fly = function(sender, args)
local playerToFly = args[1]
if playerToFly then
local player = findPlayer(playerToFly)
if player then
local body = Instance.new("BodyVelocity")
body.Name = "FlyVelocity"
body.Parent = player.Character.HumanoidRootPart
body.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
body.Velocity = Vector3.new(0,0,0)
end
end
if args[1] == "me" then
if sender then
local body = Instance.new("BodyVelocity")
body.Name = "FlyVelocity"
body.Parent = sender.Character.HumanoidRootPart
body.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
body.Velocity = Vector3.new(0,0,0)
end
end
end
So basically, you can try making a new BodyVelocity inside the playerâs characterâs HumanoidRootPart, set the MaxForce to Vector3.new(math.huge,math.huge,math.huge), but the velocity to Vector3.new(0,0,0) first. Then whenever the characterâs Humanoidâs MoveDirection changes, request for the clientâs cameraâs CFrame (workspace.CurrentCamera.CFrame) and the key pressed. Sorry Iâm not able to help you with things more than that, because I donât really do much with body control in my experiences, and I also have a lot of homework to do right now. So hopefully this gives you some things you might want to use. Another thing, if you just want to make a fly command, you could just use Kohlâs Admin. Finally, if the reason you want to make a fly command is to look at the other players, you could just use Shift + P in a Roblox server and use Robloxâs built in Free Cam for the developers of the game. Anyways, gotta do homework, sorry!
Well first off, youâll have to detect where exactly the Humanoid is moving using the Running Event I suppose, I donât think a BodyVelocity would be the best case in this scenario since itâll only apply âconstant forceâ to what youâre trying to accomplish
You could potentially send a RemoteEvent from the client to the server, so that itâd detect the UserInputService.InputBegan/InputEnded events depending on which key you pressed (W, A, S, D) to make the Character in that specific way
Thing with using mobile, is that youâll have to find a wrap-around on getting where the Character would face next in relation to the thumbstick
Thereâs a lot to keep in mind with a simple fly command, maybe you could use a BodyForce instead so that it only applies âforceâ when necessary but Iâm unsure
And I would need to have 2 remote events because I tried calling commands inside of local it doesnt work but thats fine I will do that I just need an example
--LocalScript inside StarterPlayerScripts
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local UIS = game:GetService("UserInputService")
local MovesetKeys = {
Enum.KeyCode.A, --This would be left
Enum.KeyCode.D, --Right
Enum.KeyCode.W, --Forwards
Enum.KeyCode.S --Backwards
}
local CurrentKeyHit = nil --There's no current key set
UIS.InputBegan:Connect(function(Input, Chatted)
if Chatted then
return
end
if table.find(MovesetKeys, Input.KeyCode) then
if Input.KeyCode == MovesetKeys[1] then
CurrentKeyHit = "Left"
elseif Input.KeyCode == MovesetKeys[2] then
CurrentKeyHIt = "Right"
elseif Input.KeyCode == MovesetKeys[3] then
CurrentKeyHit = "Forwards"
elseif Input.KeyCode == MovesetKeys[4] then
CurrentKeyHit = "Backwards"
else
CurrentKeyHit = nil
end
Event:FireServer(CurrentKeyHit)
end
end)
--Server Script inside ServerScriptService
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
Event.OnServerEvent:Connect(function(Player, Key)
local BodyForce
local Char = Player.Character
if Char.HumanoidRootPart:FindFirstChild("BodyForce") then
BodyForce = Char.HumanoidRootPart.BodyForce
else
local Force = Instance.new("BodyForce")
Force.Parent = Char.HumanoidRootPart
BodyForce = Force
end
if Key == "Left" then
BodyForce.Force = Char.HumanoidRootPart.RightVector * -25
elseif Key == "Right" then
BodyForce.Force = Char.HumanoidRootPart.RightVector * 25
elseif Key == "Forwards" then
BodyForce.Force = Char.HumanoidRootPart.LookVector * 25
elseif Key == "Backwards" then
BodyForce.Force = Char.HumanoidRootPart.LookVector * -25
end
end)