Categories > Coding > Lua >

Yo how to make a fly toggle in rayfield ui

Posts: 17

Threads: 10

Joined: Sep, 2022

Reputation: 0

Posted

So basically as the title says i need to make a fly toggle in rayfield ui how do i do it because always i can only turn it on and cant turn it off can some help me? please.

  • 0

Posts: 0

Threads: 0

Joined: ?

Reputation:

Replied

Rayfield should have a CreateToggle feature (I haven't used in awhile)

Make your fly function, something like this I guess.

function fly(State) --// We use state to determine true or false, so if the fly is on or off.
     if State == true then
          --// stuff
     end
end

CreateToggle({
      name = "dds",
      sum = false,
      func = function(Value)
           fly(Value)
      end
})
  • 0

Haruka

STD Testing Center

Posts: 53

Threads: 3

Joined: Feb, 2023

Reputation: 5

Replied

local Player = game.Players.LocalPlayer
local Fly = false

-- create the button
local FlyButton = RaycastUI.CreateButton("Fly", "Toggle flying on/off")
FlyButton.Position = UDim2.new(0.5, 0, 0.8, 0)
FlyButton.Size = UDim2.new(0.2, 0, 0.1, 0)

-- set up the button click event
FlyButton.MouseButton1Click:Connect(function()
    Fly = not Fly -- toggle the fly variable

    if Fly then
        -- enable flying
        Player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Flying)
        FlyButton.Text = "Fly: ON"
    else
        -- disable flying
        Player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
        FlyButton.Text = "Fly: OFF"
    end
end)
  • 0

https://media.discordapp.net/attachments/979069297374671018/1078367228593971362/VelvetSiggy.png

 

 

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )