Make tool get thrown with e?

hey everyone rn I want to throw a tool with a secondary attack but instead of clicking with mouse when I throw I want it to get thrown with Keybord E cuz I already got an attack for click and It’s hard cuz the Item that should get thrown is in the replicated storage in a folder and It’s a union and I want it to get thrown with e and later I want it to be also thrown when Image Button is pressed but anyways can someone turn this from click into e and the script is is serverscriptservice

local rep = game:GetService("ReplicatedStorage")
local fireball = rep:WaitForChild("Fireball")
local CameraShakeRemote = rep:WaitForChild("ShakeCamera")

local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

local Info = TweenInfo.new(0.25, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false)
local FX = rep:WaitForChild("FX")

local debounce = false
local cooldownTime = 2

fireball.OnServerEvent:Connect(function(player, mouse)
	if debounce then return end  
	debounce = true  

	local char = player.Character
	local humRP = char:WaitForChild("HumanoidRootPart")

	local function ShakeCamera(Magnitude, Roughness, FadeIn, FadeOut, Length)
		CameraShakeRemote:FireClient(player, {Magnitude, Roughness, FadeIn, FadeOut, Length})
	end

	local folder = Instance.new("Folder")
	folder.Name = "Fireball FX"
	folder.Parent = game.Workspace

	local Fireball = FX:WaitForChild("Fireball"):Clone()
	Fireball.Parent = folder

	-- **Spawn the sword slightly in front of the player**
	Fireball.CFrame = humRP.CFrame * CFrame.new(0, 0, -2)

	-- **Calculate the correct throw direction**
	local direction = (mouse - Fireball.Position).unit

	-- **Correct Rotation (Make the sword face forward properly)**
	Fireball.CFrame = CFrame.lookAt(Fireball.Position, mouse) * CFrame.Angles(math.rad(90), 0, 0)

	local bv = Instance.new("BodyVelocity")
	bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	bv.Velocity = direction * 150  -- Ensure proper direction
	bv.Parent = Fireball

	Fireball.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") and not hit:FindFirstAncestor(char.Name) then
			local eHum = hit.Parent:FindFirstChild("Humanoid")
			local ehumRP = hit.Parent:FindFirstChild("HumanoidRootPart")

			if eHum then
				eHum:TakeDamage(100)
				ShakeCamera(5, 10, 0, 0.5, 1)

				local VFX1 = FX:WaitForChild("VFX1"):Clone()
				local VFX2 = FX:WaitForChild("VFX2"):Clone()
				local SWave = FX:WaitForChild("FlatShockWave"):Clone()

				local Efolder = Instance.new("Folder")
				Efolder.Name = "EXFolder"
				Efolder.Parent = game.Workspace

				VFX1.Parent = Efolder
				VFX1.CFrame = ehumRP.CFrame * CFrame.new(0, -1.5, 0)
				local Tween1 = TweenService:Create(VFX1, Info, {Size = Vector3.new(21.639, 21.689, 19.643), Transparency = 1})
				Tween1:Play()

				VFX2.Parent = Efolder
				VFX2.CFrame = ehumRP.CFrame * CFrame.new(0, -1.5, 0)
				local Tween2 = TweenService:Create(VFX2, Info, {Size = Vector3.new(20.142, 20.189, 19.145), Transparency = 1})
				Tween2:Play()

				SWave.Parent = Efolder
				SWave.CFrame = ehumRP.CFrame * CFrame.new(0, -2.7, 0) * CFrame.Angles(math.rad(-90), 0, 0)
				local Tween3 = TweenService:Create(SWave, Info, {Size = Vector3.new(27.348, 27.348, 4.868), Transparency = 1})
				Tween3:Play()

				local connection
				connection = RunService.Heartbeat:Connect(function()
					VFX1.CFrame = VFX1.CFrame * CFrame.Angles(0, math.rad(-15), 0)
					VFX2.CFrame = VFX2.CFrame * CFrame.Angles(0, math.rad(15), 0)
				end)

				wait(0.15)
				game.Debris:AddItem(folder, 0.5)

				Tween3.Completed:Connect(function()
					wait(1.5)
					local Tween4 = TweenService:Create(VFX1, Info, {Transparency = 1})
					Tween4:Play()

					local Tween5 = TweenService:Create(VFX2, Info, {Transparency = 1})
					Tween5:Play()

					local Tween6 = TweenService:Create(SWave, Info, {Transparency = 1})
					Tween6:Play()

					Tween6.Completed:Connect(function()
						game.Debris:AddItem(Efolder, 1)
					end)
				end)
			end
		end
	end)

	wait(1)
	game.Debris:AddItem(Fireball, 2)

	task.wait(cooldownTime)
	debounce = false  
end)
1 Like

It’s not possible via a script from ServerScriptService. You need to code it via the client script in question with ContextActionService, that will allow you to use an ImageButton like here:

Tool.Equipped:Connect(function()
local ContextActionService = game:GetService("ContextActionService")
ContextActionService:BindAction("ThrowItem", FUNCTIONTOTHROW, true, Enum.KeyCode.E)
--[[
ContextActionService:SetImage("ThrowItem", YOURIMAGE)
ContextActionService:SetPosition("ThrowItem", YOURPOSITION)
]] -- FOR IMAGES
ContextActionService:SetTitle("ThrowItem", "Throw")
end)

Tool.Unequipped:Connect(function()
local ContextActionService = game:GetService("ContextActionService")
ContextActionService:UnbindAction("ThrowItem")
end)

Thus, you can get:

  • The way to fire a fireball with E
  • Support for mobile
  • Support for your image project and position

Hope it helps!

1 Like