How to make /Fly and /Unfly Command?

Hello so I want to make a admin type of gamepass so in there. I want 2 commands like /fly and /unfly,
and I want people to buy gamepass to use that command. so I tried few ways but it didn’t work. Can anyone help me with it?

2 Likes

Assuming that you already have a fly script:

local _settings = {
	command = "/fly",
	gamepassId = 0
}

local MarketplaceService: MarketplaceService = game:GetService("MarketplaceService")

local function onPlayerAdded(player: Player)
	if not MarketplaceService:UserOwnsGamePassAsync(player.UserId, _settings["gamepassId"]) then return end
	
	local function onChatted(message: string)
		if message ~= string.lower(_settings["command"]) then return end
		
		--Fly
	end
	
	player.Chatted:Connect(onChatted)
end

game:GetService("Players").PlayerAdded:Connect(onPlayerAdded)
1 Like

Instead of that can you make a flying tool. like when you hold the tool/gear you can fly?

just need the script of flying tool

I’m not sure how to do the flying part, I’m not a script wonder, sorry.

Perhaps someone that reads this could provide a fly script?

And there’s tons of Youtube video’s out there on how to make a fly script.

For the tool I will provide you that code.

1 Like

This will be a LocalScript inside the tool.

local RunService = game:GetService("RunService")

local Tool = script.Parent
local Equipped = false

Tool.Equipped:Connect(function()
    Equipped = true
    Tool.Unequipped:Wait()
    Equipped = false
end)

RunService.RenderStepped:Connect(function()
    if Equipped then
        -- Fly Code
    end
end)
2 Likes

Isn’t it better to remove that whole renderstepped event?

--Only give this tool to players that own the gamepass!

local tool: Tool = script.Parent

local function onEquipped()
	--Fly
end

local function onUnequipped()
	--Unfly
end

tool.Equipped:Connect(onEquipped)
tool.Unequipped:Connect(onUnequipped)
2 Likes

everything is good, I spent 4 hours to make a fly script but laggy and not worth it. so I just need a good smooth flying script right now for the tool.

1 Like

I suggest you make a new topic with your old fly code and people can improve it.

1 Like

Hey, I finished making a fly script. Here is the script,

local UIS = game:GetService('UserInputService')

local Player = game:GetService('Players').LocalPlayer
local Camera = workspace.CurrentCamera

local Flying = false

function toggleFly()
	Flying = not Flying
	
	if Flying then
		local char = Player.Character
		local rootPart:BasePart = char:WaitForChild('HumanoidRootPart')
		local hum:Humanoid = char:WaitForChild('Humanoid')
		hum.PlatformStand = true
		local currentCF = rootPart.CFrame

		while Flying and task.wait() do
			local add = Vector3.new(0,0,0)

			if UIS:IsKeyDown(Enum.KeyCode.W) then add += Camera.CFrame.LookVector end
			if UIS:IsKeyDown(Enum.KeyCode.S) then add -= Camera.CFrame.LookVector end
			if UIS:IsKeyDown(Enum.KeyCode.D) then add += Camera.CFrame.RightVector end
			if UIS:IsKeyDown(Enum.KeyCode.A) then add -= Camera.CFrame.RightVector end
			if UIS:IsKeyDown(Enum.KeyCode.E) then add += Camera.CFrame.UpVector end
			if UIS:IsKeyDown(Enum.KeyCode.Q) then add -= Camera.CFrame.UpVector end

			rootPart.AssemblyLinearVelocity = Vector3.zero
			rootPart.AssemblyAngularVelocity = Vector3.zero

			currentCF += add
			rootPart.CFrame = CFrame.lookAt(
				currentCF.Position,
				currentCF.Position + (Camera.CFrame.LookVector * 2)
			)
		end

		hum.PlatformStand = false
	end
end

Player.Chatted:Connect(function(MSG)
	if MSG == '/fly' then
		toggleFly()
    elseif MSG == '/unfly' then
        Flying = false
	end
end)
11 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.