How to make plr Fly if boolvalue is true

I want when boolvalue (PlrVal) is true then
the player will immediately fly without pressing the keycode.E
image
so instead of using Keycode, it check if boolvalue is true or not
if true then run the function/play

the line code, click the Arrow
local KeyCode = Enum.KeyCode.E

--im just putting the keycode section here

UIS.InputBegan:Connect(function(key, gameProcessed)
	if gameProcessed then return end
	if key.KeyCode == KeyCode then
		if Flying == false then
			Flying = true
			if Character:FindFirstChild("HumanoidRootPart") then
				v10:Play(0.1, 1, 1)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, false)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, false)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.Freefall, false)
				Character.HumanoidRootPart.Running.Volume = 0
				Humanoid:ChangeState(6)
				BodyVelocity.Parent = Character.HumanoidRootPart
				v3.Parent = Character.HumanoidRootPart
			end
		else
			Flying = false
			Flymoving.Value = false
			Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, true)
			Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, true)
			Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, true)
			Humanoid:SetStateEnabled(Enum.HumanoidStateType.Freefall, true)
			Character.HumanoidRootPart.Running.Volume = 0.65
			Humanoid:ChangeState(8)
			BodyVelocity.Parent = Character
			v3.Parent = Character
			v10:Stop()
			v11:Stop()
		end
	end
end)

Something like this:

local Value = game.ReplicatedStorage.Value

Value:GetPropertyChangedSignal("Value"):Connect(function()
	if Value.Value == true then
		print("the value is true")
	else
		print("the value is false")
	end
end)
1 Like

I have added the fly logic inside a function so we would call it later if the plrval changed to true:

local KeyCode = Enum.KeyCode.E

--im just putting the keycode section here

local function fly()
	if Flying == false then
		Flying = true
		if Character:FindFirstChild("HumanoidRootPart") then
			v10:Play(0.1, 1, 1)
			Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, false)
			Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, false)
			Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
			Humanoid:SetStateEnabled(Enum.HumanoidStateType.Freefall, false)
			Character.HumanoidRootPart.Running.Volume = 0
			Humanoid:ChangeState(6)
			BodyVelocity.Parent = Character.HumanoidRootPart
			v3.Parent = Character.HumanoidRootPart
		end
	else
		Flying = false
		Flymoving.Value = false
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, true)
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, true)
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, true)
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.Freefall, true)
		Character.HumanoidRootPart.Running.Volume = 0.65
		Humanoid:ChangeState(8)
		BodyVelocity.Parent = Character
		v3.Parent = Character
		v10:Stop()
		v11:Stop()
	end
end

UIS.InputBegan:Connect(function(key, gameProcessed)
	if gameProcessed then return end
	if key.KeyCode == KeyCode then
		fly()
	end
end)

script.plrval:GetPropertyChangedSignal("Value"):Connect(function()
	if script.plrval.Value then
		fly()
	end
end)


1 Like

oh yea btw this localscript, is on startercharacterscript

@JAcoboiskaka1121 @VonsRevenges
I tried it and it didn’t work, maybe if you want to see the code the full version is here.

full ver
local KeyCode = Enum.KeyCode.E
local Value = script.plrval

local HoverAnimID = "rbxassetid://"
local FlyAnimID = "rbxassetid://"
local WindSoundEnabled = true

local BodyVelocity = script:WaitForChild("BodyVelocity"):Clone()
local v3 = script.BodyGyro:Clone()
local Character = script.Parent
local Humanoid = Character:FindFirstChild("Humanoid") or Character:WaitForChild("Humanoid")
BodyVelocity.Parent = Character
v3.Parent = Character
local Hover = Instance.new("Animation")
Hover.AnimationId = HoverAnimID
local Fly = Instance.new("Animation")
Fly.AnimationId = FlyAnimID
local Sound1 = Instance.new("Sound", Character.HumanoidRootPart)
Sound1.SoundId = "rbxassetid://3308152153"
Sound1.Name = "Sound1"
if WindSoundEnabled == false then
	Sound1.Volume = 0
end
local v10 = Humanoid.Animator:LoadAnimation(Hover)
local v11 = Humanoid.Animator:LoadAnimation(Fly)
local Camera = game.Workspace.Camera
local function u2()
	if Humanoid.MoveDirection == Vector3.new(0, 0, 0) then
		return Humanoid.MoveDirection
	end
	local v12 = (Camera.CFrame * CFrame.new((CFrame.new(Camera.CFrame.p, Camera.CFrame.p + Vector3.new(Camera.CFrame.lookVector.x, 0, Camera.CFrame.lookVector.z)):VectorToObjectSpace(Humanoid.MoveDirection)))).p - Camera.CFrame.p;
	if v12 == Vector3.new() then
		return v12
	end
	return v12.unit
end
local Flymoving = script.Flymoving
local TweenService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
local Flying = false

game:GetService("RunService").RenderStepped:Connect(function()
	if script.Parent == Character then
		if Flying == true then
			Humanoid:ChangeState(6)
			v3.CFrame = game.Workspace.Camera.CFrame
			if u2() == Vector3.new(0, 0, 0) then
				Flymoving.Value = false
			else
				Flymoving.Value = true
			end
			TweenService:Create(BodyVelocity, TweenInfo.new(0.3), {Velocity = u2() * 350}):Play()
		end
		
	end
end)

Flymoving.Changed:Connect(function(p1)
	if p1 == true then
		TweenService:Create(Camera, TweenInfo.new(0.5), {FieldOfView = 100}):Play()
		v10:Stop()
		Sound1:Play()
		v11:Play()
		return
	end
	if p1 == false then
		TweenService:Create(Camera, TweenInfo.new(0.5), {FieldOfView = 70}):Play()
		v11:Stop()
		Sound1:Stop()
		v10:Play()
	end
end)

local xractivated = false

script.plrval:GetPropertyChangedSignal("Value"):Connect(function()
	if script.plrval.Value then
		if Flying == false then
			Flying = true
			if Character:FindFirstChild("HumanoidRootPart") then
				v10:Play(0.1, 1, 1)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, false)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, false)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
				Humanoid:SetStateEnabled(Enum.HumanoidStateType.Freefall, false)
				Character.HumanoidRootPart.Running.Volume = 0
				Humanoid:ChangeState(6)
				BodyVelocity.Parent = Character.HumanoidRootPart
				v3.Parent = Character.HumanoidRootPart
			end
		else
			Flying = false
			Flymoving.Value = false
			Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, true)
			Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, true)
			Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, true)
			Humanoid:SetStateEnabled(Enum.HumanoidStateType.Freefall, true)
			Character.HumanoidRootPart.Running.Volume = 0.65
			Humanoid:ChangeState(8)
			BodyVelocity.Parent = Character
			v3.Parent = Character
			v10:Stop()
			v11:Stop()
		end
	end
end)

Oh, sorry I forgot to mention, I don’t think it works on the client, when I tested it and switched to the server it was working.

EDIT: Nvm I put my script in a local script and the value under the script and it works, I think you need to change the player value in the player itself.

1 Like

how do you made it woking on the server

It will not work as you can’t detect the keycode on server.

1 Like

Im not talking about the whole thing, im talking about I snippet I coded.

1 Like