You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
What I want to achieve is a sort of gravitational tug, which all in itself sounds the best way to put it. Basically, I want to make flying, but not as an admin command. The thing is, I want to make for one character specifically, the game checks if you’re ONLY that character by seeing if you have a certain string value, e.g. “Flying-man” and when you press F, only in the air, it lowers your fall speed. I’ve seen games do it, but I want it to also play a different falling animation when you’re falling.
If you didn’t understand that, let me make it more simpler.
You morph into the specific character that has this ability, that no one else can use. The game checks if you’re that character by checking to see if the character has the correct string value parented to it. On key pressed, preferably F, it lowers your fall speed and plays an animation. BUT, it won’t work when you’re on the ground, because I want to make a cooldown for it, so it’s not abused notoriously.
What is the issue? Include screenshots / videos if possible!
Issue is, I’ve looked through different types of keybind and fall constant topics on the Dev Forum, and looked at Roblox’s documents on scripting, but truth be told I have no clue where to start, so I’d be grateful if someone pointed me in the right direction.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Dev Forum and YouTube, but I don’t have all the time I need to make my game everyday.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
(Code originally by @miguel555555ft, I understand what string values are, and variables, but other than knowing WHAT they are, I have no clue how to do the magic ya’ll do and put them together to create something awesome.)
Script I thought would work:
--
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
--This is a service to check player inputs, check the docs of this service to know more.
local UserInputService = game:GetService("UserInputService")
--[[
Everytime the player press a button or so something in the game, will fire a input and will
call this function below.
--]]
UserInputService.InputBegan:Connect(function(input, interaction)
--Checking if the player dont fired a input while interacting with something in the game
if not interaction then
if input.KeyCode == Enum.KeyCode.F then
if Character then
--Checking if StringValue exist in the character, you can name with what name you want, but you will need to change the name here too
if Character:FindFirstChild("StringValue") then
if Character.StringValue.Value == "Flying-man" then
newvalue.Velocity = Vector3.new(0, -5, 0)
elseif Character.StringValue.Value == !"Flying-man" then
--Nothing happens.
end
end
end
end
end
end)
People never answer to my topics, I don’t know why. This seems so simple, yet I can’t grasp the answer yet.
What I meant by,“plays an animation”, I meant it swaps the new flying animation for the normal falling animation until you hit the ground. But once you hit the ground, I want the original animation to be the primary falling animation.
Nothing happens because you are triggering the same event twice, so it’s obviously going to trigger the first and not the second, in the second you wanted to check if the character does not have the “Flying-man” value? If so, just do:
elseif Character.StringValue.Value ~= "Flying-man" then
--what you want here.
end
to check if the player is off the ground, use Humanoid.FloorMaterial (you want it to be Enum.Material.Air),
for the animation play the animation while shooting a raycast downwards continously (i think it would work), and if it touches something, you succesfully landed on the ground, to then stop the animation, and in the script, change
if not interaction then
-- blah blah blah
end
CHANGE IT TO
if interaction then return end
-- continue blah blah blah here
i said to use raycasts because humanoid.Landed doesnt always fire, which could lead in the animation not stopping sometimes
Thank you! But I don’t know how raycasts work. I’ve been hearing about it in my favorite developers videos and stuff, and he apparently uses it so that his morphs heads face the mouse, but only on a certain rotation directory. If you could explain how it works, or have a documentary I could learn from, I’d be extremely grateful.
Raycasting
This is an example on how to raycast a ray downwards
-- this goes in starter pack
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:FindFirstChild("HumanoidRootPart")
local rayDirection = Vector3.new(0, -10, 0) -- 10 studs downwards
local params = RaycastParams.new()
params.FilterDescendantInstances = {character}
params.FilterType = Enum.RaycastingFilterType.Exclude -- this might be wrong, check documentation
local rayResult = workspace:Raycast(hrp, rayDirection, params)
if rayResult then -- means raycast touched something
print(rayResult.Instance.Name)
print(rayResult.Distance)
end
this should shoot a ray downwards from the humanoidrootpart and print what it touched and how far it was. for a slow fall effect you would make the ray shorter, which would be the distance of the humanoidrootparts center to the bottom of the legs (i dont know how many studs it is)
Hmm, one concern though…?
Why does it say that it goes in starter pack? I mean, I’m not double guessing help, but I don’t want the flying ability to be part of a tool. Lol.
Would this also work by shooting a remote event for it recieve?
its in starter pack so that it automatically goes into the player character, not necessarily a tool, if you were to put in starter character scripts, then it would work the same, but you would have to change
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
to
local character = script.Parent
its just that its common practice for me to include local scripts in starter pack, even though i could even place them in starter GUI and they would work the same, by themselves
you could send remote events, but i dont see why that would be necessary, like for example, if you were to make a sprint script, make it client sided, because exploiters can change their walkspeed, can noclip, and can fly anyways, but its up to you honestly, its just that comunicating in to the server and back will have some lag
Alright, thank you! You’re the first person to acknowledge my needs and not say, “Firing to server doesn’t cause lag, as long as it’s not initiated all at once.” I’ll try implementing my own parts to your script template and see how it’d work.