i have been awake since 3 am because i’m sick ash, but that doesn’t stop my sigma coding grind
right;
i wanna do vaulting, i want to make it safe but also want to avoid handling it on the server (because i think that would be bad!)
step by step of what i want to do:
- player jumps
- invisible detector part gets created
- if nothing is colliding with it, allow the player to press space to vault
- move the player to the position of the detector part using tween service
here’s a showcase:
now the very obvious issues is that this code very exploitable, i am very aware of it
but i want to avoid doing this on the server, because i feel like repetitively updating some stupid part’s cframe every frame (While it exists) would be extremely bad to do,
additionally it would be tough to communicate between client and server, especially when i want to tell the client they can vault
this is my current code
local tService = game:GetService("TweenService")
local uInputService = game:GetService("UserInputService")
-- Tween parameters;
local vaultTweenParams = TweenInfo.new(
1,
Enum.EasingStyle.Back,
Enum.EasingDirection.Out
)
-- Player variables;
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid: Humanoid = char:WaitForChild("Humanoid")
local head: BasePart = char:WaitForChild("Head")
-- Functions;
local function CreateDetectorPart()
local detectorPart = Instance.new("Part")
detectorPart.Size = Vector3.new(4, 0.5, 2)
detectorPart.Position = head.CFrame.Position + Vector3.new(0, 0.5, 2) -- Right at the top of the head
-- and slightly infront of the player
detectorPart.CanCollide = false
detectorPart.Parent = workspace
detectorPart.Name = "VaultDetector"
return detectorPart
end
local function MoveDetectorPart(detectorPart: BasePart)
local inputConnection = nil
while detectorPart do
local newPosition = head.CFrame.Position + Vector3.new(0, 0.5, 2)
detectorPart.CFrame = CFrame.new(newPosition)
local detectionBounds = workspace:GetPartsInPart(detectorPart)
if #detectionBounds > 0 then
detectorPart.Color = Color3.fromRGB(255)
continue
end
detectorPart.Color = Color3.fromRGB(0,255,0)
inputConnection = uInputService.InputBegan:Connect(function(input)
local key = input.KeyCode
if key ~= Enum.KeyCode.Space then return end
-- TODO: FINISH ME!
inputConnection:Disconnect()
end)
task.wait()
end
if inputConnection then inputConnection:Disconnect() end
end
local function OnStateChanged(old: Enum, new: Enum)
if new ~= Enum.HumanoidStateType.Freefall or new ~= Enum.HumanoidStateType.Jumping then
local detectorPart = workspace:FindFirstChild("VaultDetector")
if detectorPart then detectorPart:Destroy() end
return
end
local detectorPart = CreateDetectorPart()
-- This function isn't very much finished yet, don't worry about that!!
end