Hello, I’ve wanted to try and make my fireball ability charge-able, making it deal more damage and create a larger explosion plus giving it more room to aim.
Currently the ability just instantly casts upon pressing the button.
I know I have to use the UserInputService InputBegan and InputEnded, but I’m confused on how I can replicate its effects into the server. Also trying to make this work on mobile and console. :,)
So in summary, I just need a general base on how to do it…
I went ahead and made a simple script that will provide somewhat of a foundation to which you can further make your code off of. The script is easily customizable and already made spam-proof with a debounce. If you have questions, let me know.
What you need:
- 2x RemoteEvent
LocalScript in StarterPlayerScripts
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local player = Players.LocalPlayer --//Defines who the script will be for
local debounce = false
if input.KeyCode == Enum.KeyCode.E and debounce == false then
debounce = true
ReplicatedStorage.StartCharge:FireServer(player) --//Starts the charge serversided
if input.KeyCode == Enum.KeyCode.E and player:FindFirstChild("Charging") then
ReplicatedStorage.EndCharge:FireServer(player) --//Ends the charge.
debounce = false
print("Debounce set to ", debounce)
local ReplicatedStorage = game:GetService("ReplicatedStorage") --//Clear a path to the RemoteEvents
local charging = Instance.new("IntValue") --//Create the charge
charging.Parent = player
charging.Name = "Charging"
charging.Value = 0 --//Charge count
while player:FindFirstChild("Charging") do
player.Charging.Value += 1
task.wait(1) --//Charge will increase by 1 every 1 second. Customize how you'd like
print(player.Name .. " attacked with a charge strength of " .. player.Charging.Value)
Before the next line it gets destroyed, this player.Charging.Value will be your charge value.
Use this value as a factor to determine the strength/stage of the charge.
player.Charging:Destroy() --//Delete for proper reset of charge