--[[
================================================== Copyright Valor 2022-2023, all rights reserved ==================================================
================================================================== 25 April, 2022 ==================================================================
== PURPOSE: This is script handles and works with the keybinds for the game. This is specific for every textbox in the settings menu.
--]]
-- Note: This specific script acts as both the module and local script for the keybind mechanics for the game. This is but a text for the whole idea on how it would work.
-- Add. Notes: THIS IS SPECIFIC FOR THE SHIFT KEY (USED FOR TEXTING RN) WHICH IN TURN IS USED FOR DASHING.
-- Local Script
local UserInputService = game:GetService("UserInputService")
local g_replicatedstorage = game:GetService("ReplicatedStorage")
local g_plr = game:GetService("Players").LocalPlayer
local re_keybindchange = g_replicatedstorage.rs_Main.m_Events:WaitForChild("re_keybindchange")
local g_keybinds = require(g_replicatedstorage.rs_Main.m_Modules.mod_keybinds)
local sc_keybind = script.Parent -- Specific for each textbox where the player enters their desired keybind.
--[[
PURPOSE: This function sends the newly inputted keybind in the textbox to the dictionary module, so it can be called for the mechanics.
--]]
local function SendKeybind()
g_keybinds["Dash"] = sc_keybind.Text
end
--[[
PURPOSE: This is to cap the keybind changing textbox's text to just 1 (one) keyboard keybind.
--]]
sc_keybind.Changed:Connect(function()
sc_keybind.Text = sc_keybind.Text:sub(1, 1)
end
local function Keybind(input, isTyping)
if isTyping then
return
end
if input.UserInputType == Enum.KeyCode[sc_keybind.Text] then
SendKeybind()
end
end
UserInputService:Connect(Keybind)
sc_keybind.Activated:Connect(SendKeybind)
re_keybindchange.OnClientEvent:Connect(SendKeybind)
--Module Script
local keybinds = {
Dash = "Shift"
}
return keybinds
-- Server Script
-- THIS IS FOR DASHING IN THE GAME.
local g_replicatedstorage = game:GetService("ReplicatedStorage")
local g_plr = game:GetService("Players").LocalPlayer
local UserInputService = game:GetService("UserInputService")
local g_character = g_plr.Character or g_plr.CharacterAdded:Wait()
local p_Root = g_character:WaitForChild("HumanoidRootPart")
local g_keybinds = require(g_replicatedstorage.rs_Main.m_Modules.mod_keybinds)
local re_keybindchange = g_replicatedstorage.rs_Main.m_Events:WaitForChild("re_keybindchange")
--[[
PURPOSE: This hopfully helps with the server changing the specific player's new keybind so it's useable by the server and clients to work properly.
(Aka. default: Shift, new keybind: Ctrl, server fires the new change to all clients so the player can use the new keybind so the server proceeds with the dash, along with the server.)
--]]
re_keybindchange:FireAllClients(g_keybinds.Dash)
local g_dash = 20
local g_timeDash = 0.15
local d_CanDash = false
--[[
PURPOSE: This handles the player dashing.
--]]
function DashForward(p_Root)
local i = Instance.new("BodyPosition")
i.MaxForce = Vector3.new(1000000, 0, 1000000)
i.P = 100000
i.D = 2000
i.Position = (p_Root.CFrame * CFrame.new(0, 0, -g_dash)).Position
coroutine.wrap(function()
wait(0.2)
i:Destroy()
end)()
end
--[[
PURPOSE: This handles the input for when the player presses their desired key they used to dash.
--]]
UserInputService.InputBegan:Connect(function(input, isTyping)
if isTyping then
return
end
if input.KeyCode == Enum.KeyCode[g_keybinds.Dash] then
if d_CanDash == true then
d_CanDash = false
DashForward(p_Root)
else
d_CanDash = true
coroutine.wrap(function()
wait(g_timeDash)
d_CanDash = false
end)()
end
end
end)
Om dit project op uw website in te sluiten, kopieer de volgende code en plak deze in de HTML van uw website: