How would I change this to a keybind?

I have a spell and I want to turn it into a keybind. I’ve tried editing it but it’s not working. I also added a print statement after the keybind is pressed and that didn’t print so I don’t know where it stops working. There’s nothing in output.

original script

		--// Services 
local Players = game:GetService('Players')
local TweenService = game:GetService('TweenService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')

--// Items
--# Player
local Player = Players.LocalPlayer
local Character = Player.Character

local Mouse = Player:GetMouse()

local CurrentCamera = workspace.CurrentCamera

--# Objects
local Events = ReplicatedStorage:FindFirstChild('HISSES')

local SpellEvent = Events:FindFirstChild('SpellEvent')

--# Variables
local SpellInfo = {
	['Spell'] = 'corporis ascendum',
	['cooldownTime'] = 3,

	['cooldownActive'] = false
}
--// Scripts
--# Tween
local function Tween(Object, Goals)
	local Tween = TweenService:Create(Object, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), Goals)
	return Tween
end

--# handleHealing
local function handleTelekinesis(TargetCharacter)
	--# Start Power
	-- Cooldown
	SpellInfo['cooldownActive'] = true
	delay(SpellInfo['cooldownTime'], function() SpellInfo['cooldownActive'] = false end)
	
	local target  = Mouse.Target.Parent
	SpellEvent:FireServer("Telekinesis",target, "Start", Mouse.Hit.Position)
	
	for i = 1, 100 do 
		
		SpellEvent:FireServer("Telekinesis",target, "Update", Mouse.Hit.Position)
		
		wait(0.1)
		
	end

	SpellEvent:FireServer("Telekinesis",target, "End", Mouse.Hit.Position)
	
end

--# handleInput
Player.Chatted:Connect(function(msg)
	--# Check For Spell
	if msg == SpellInfo['Spell'] and not SpellInfo['cooldownActive'] and Player.Team.Name ~= "Visitors"  then
		
		local buttonFunction
		buttonFunction = Mouse.Button1Down:Connect(function()
			--# playerCheck
			for _, workspaceDescendant in pairs(workspace:GetDescendants()) do
				if workspaceDescendant:FindFirstChildWhichIsA('Humanoid') then
					if Mouse.Target:IsDescendantOf(workspaceDescendant) then
						handleTelekinesis(workspaceDescendant)
						buttonFunction:Disconnect()
					end
				end
			end
		end)
	end
end)

edited version

		--// Services 
local Players = game:GetService('Players')
local TweenService = game:GetService('TweenService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')

--// Items
--# Player
local Player = Players.LocalPlayer
local Character = Player.Character

local Mouse = Player:GetMouse()

local CurrentCamera = workspace.CurrentCamera

--# Objects
local Events = ReplicatedStorage:FindFirstChild('HISSES')

local SpellEvent = Events:FindFirstChild('SpellEvent')

--# Variables

local SpellInfo = {
	['Key'] = Enum.KeyCode.U,
	['cooldownTime'] = 3,
	["cooldownActive"] = false
}
--// Scripts
--# Tween
local function Tween(Object, Goals)
	local Tween = TweenService:Create(Object, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), Goals)
	return Tween
end

--# handleHealing
local function handleTelekinesis(TargetCharacter)
	--# Start Power
	-- Cooldown
	SpellInfo['cooldownActive'] = true
	delay(SpellInfo['cooldownTime'], function() SpellInfo['cooldownActive'] = false end)
	
	local target  = Mouse.Target.Parent
	SpellEvent:FireServer("Telekinesis",target, "Start", Mouse.Hit.Position)
	
	for i = 1, 100 do 
		
		SpellEvent:FireServer("Telekinesis",target, "Update", Mouse.Hit.Position)
		
		wait(0.1)
		
	end

	SpellEvent:FireServer("Telekinesis",target, "End", Mouse.Hit.Position)
	
end

--# handleInput
Mouse.KeyDown:Connect(function(key)
	--# Check For Spell
	if key == Enum.KeyCode.U and not SpellInfo['cooldownActive'] and Player.Team.Name ~= "Visitors"  then
print("pressed U") -- this doesnt print
			--# playerCheck
			for _, workspaceDescendant in pairs(workspace:GetDescendants()) do
				if workspaceDescendant:FindFirstChildWhichIsA('Humanoid') then
					if Mouse.Target:IsDescendantOf(workspaceDescendant) then
						handleTelekinesis(workspaceDescendant)

				end
			end
		end
	end
end)

All conditions for the if statements are met. Cooldown is not active and the team is not visitors

Maybe do:

if key.KeyCode == Enum.KeyCode.U then
1 Like

i always forget to do KeyCode, thank you :sob:

this didn’t fix my issue though…

it doesnt print when i press U, and the telekinesis doesn’t start

Why don’t you try this

local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input, gameprocessed)
	if not gameprocessed then
		if input.KeyCode == Enum.KeyCode.U and not SpellInfo['cooldownActive'] and Player.Team.Name ~= "Visitors" then
--code here
end)
1 Like

It seems like it worked for you, oops.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.