RemoteFunction not working

Im trying to make an attack that has a more powerful effect the longer you hold a button, the code works perfectly fine but the only problem is if the player only taps the button, not hold it then the move stays in its charging state on the server script

–local script

local Players = game:GetService("Players")
local Player
local Character

local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local EarthSpikesEvent = Tool:WaitForChild("EarthSpikes")

local Input = game:GetService("ContextActionService")

local EarthSpikeChargeValue = 1
local EarthSpikeFired = false

local function EarthSpikes(ActionName,InputState,InputObj)
	if InputState == Enum.UserInputState.End then
		EarthSpikeFired = true
		EarthSpikesEvent:InvokeServer(InputObj.KeyCode, EarthSpikeChargeValue, true)
	else if InputState == Enum.UserInputState.Begin then
			EarthSpikesEvent:InvokeServer(InputObj.KeyCode, EarthSpikeChargeValue, false)

			repeat wait(.7)
				EarthSpikeChargeValue += 1
				if EarthSpikeChargeValue >= 5 then EarthSpikeChargeValue = 5 end
				print(EarthSpikeChargeValue)
			until EarthSpikeFired

			EarthSpikeFired = false
			EarthSpikeChargeValue = 1
		end
	end
end

function Equipped(Mouse)
	Character = Tool.Parent
	Player = Players:GetPlayerFromCharacter(Character)
	Humanoid = Character:FindFirstChild("Humanoid")
	
	Input:BindAction("EarthSpikes",EarthSpikes,false,Enum.KeyCode.E)
	
	if not CheckIfAlive() then
		return
	end
end

function Unequipped()
	Input:UnbindAction("EarthSpikes")
end

Server Script

function Events.RockSpike.OnServerInvoke(player, key, rockstocreate, attack)
	if key == Enum.KeyCode.E then
	
		if attack == false then
			 	
			Animations.RockSpikeSmash:Play()
			Humanoid.AutoRotate = false
			Animations.RockSpikeSmash:GetMarkerReachedSignal("ChargingUpAttack"):Wait()
			Animations.RockSpikeSmash:AdjustSpeed(0)	
		elseif attack then
            Animations.RockSpikeSmash:AdjustSpeed(1)
			
			--do attack
		end
	end
end
else if

I’m assuming this wasn’t intended.

else if InputState == Enum.UserInputState.Begin then

yes, this wasnt intended. I just had to remove things from the script i deemed unnecessary to my problem like tweening and somehow did that

Server script shorten.

function Events.RockSpike.OnServerInvoke(player, key, rockstocreate, attack)
	if key == Enum.KeyCode.E then
	
		if attack then
            Animations.RockSpikeSmash:AdjustSpeed(1)
			
			--do attack
			 	
		else
			Animations.RockSpikeSmash:Play()
			player.Character.Humanoid.AutoRotate = false
			Animations.RockSpikeSmash:GetMarkerReachedSignal("ChargingUpAttack"):Wait()
			Animations.RockSpikeSmash:AdjustSpeed(0)
		end
	end
end
1 Like