UserInputService stops working when you reset your character

I making an ability for a game and anytime I use the UserInputservice it works the first time but when I reset my character it just stops working. What do I need to do so this does not happen again

You might have put your LocalScript inside the StarterGui, and the StarterGui is set to “Reset On Spawn” inside its properties.

The script is in starterplayerscripts
image

local UIS = game:GetService("UserInputService")
local module = {}
local db = false
local ShockClone
local WeldConst

function module:Activate(Plr:Player,Humanoid:Humanoid)
	local Keycode = Enum.KeyCode.E
	local Animation = game.ReplicatedStorage.Abilities["Ice Barrage"]
	local Animator = Humanoid:FindFirstChildOfClass("Animator")
	local Track = Animator:LoadAnimation(Animation)
	local Char = Plr.Character or Plr.CharacterAdded:Wait()
	local ShockNormalSize = Vector3.new(5.989, 0.592, 6.125)
	local TweenService = game:GetService("TweenService")
	local Goals = TweenInfo.new(
		0.1,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.In
	)

	UIS.InputBegan:Connect(function(inp,gpe)
		if gpe then return end
		
		if inp.KeyCode == Enum.KeyCode.E  and not db then
			db = true
			Track:Play()
			
			Track:GetMarkerReachedSignal("Blast"):Once(function()
				ShockClone = game.ReplicatedStorage.Shock:Clone()
				WeldConst = Instance.new("Weld")
				ShockClone.Parent = workspace
				local ShockTween = TweenService:Create(ShockClone,Goals,{["Size"] = ShockNormalSize})
				local ShockTween2 = TweenService:Create(ShockClone,Goals,{["Transparency"] = 1})
				WeldConst.Parent = Char:WaitForChild("Right Arm")
				WeldConst.Part0 = Char:WaitForChild("Right Arm")
				WeldConst.Part1 = ShockClone
				ShockClone.Anchored = false
				ShockClone.CanCollide = false
				ShockClone.Size = Vector3.new(1,1,1)
				ShockClone.Position = Char:FindFirstChild("Right Arm").Position + Vector3.new(0,0,-2)
				ShockTween2:Play()
				ShockTween:Play()
			end)
		end
		
		
		
		Track.Ended:Connect(function()
			task.wait(1)
			db = false
		end)
	end)
	
end

return module

Let’s start with the obvious,

your event is disconnected when the player dies.
Why it doesn’t retrigger as the code is readded to the player again upon spawn is because
the module is already cached and will resolve in the module only running once.

Simple fix is to put the LocalScript in a environment
where it doesn’t reset on spawn such as StarterGui.

But if you insist on having the code in StarterPlayerScripts which you probably should,
try putting a player.CharacterAdded:Connect() in there, which would rerun the function.

Let me know if the issue persists,
Bellamy Lakey.

So hold lemme show you the script

—Module—

local UIS = game:GetService("UserInputService")
local module = {}
local db = false
local ShockClone
local WeldConst

function module:Activate(Char,Plr:Player,Humanoid:Humanoid)

	local Keycode = Enum.KeyCode.E
	local Animation = game.ReplicatedStorage.Abilities["Ice Barrage"]
	local Animator = Humanoid:FindFirstChildOfClass("Animator")
	local Track = Animator:LoadAnimation(Animation)
	local ShockNormalSize = Vector3.new(5.989, 0.592, 6.125)
	local TweenService = game:GetService("TweenService")
	local Goals = TweenInfo.new(
		0.1,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.In
	)
	UIS.InputBegan:Connect(function(inp,gpe)
		if gpe then return end
		
		if inp.KeyCode == Enum.KeyCode.E  and not db then
			db = true
			Track:Play()
			
			Track:GetMarkerReachedSignal("Blast"):Once(function()
				ShockClone = game.ReplicatedStorage.Shock:Clone()
				WeldConst = Instance.new("Weld")
				ShockClone.Parent = workspace
				local ShockTween = TweenService:Create(ShockClone,Goals,{["Size"] = ShockNormalSize})
				local ShockTween2 = TweenService:Create(ShockClone,Goals,{["Transparency"] = 1})
				WeldConst.Parent = Char:WaitForChild("Right Arm")
				WeldConst.Part0 = Char:WaitForChild("Right Arm")
				WeldConst.Part1 = ShockClone
				ShockClone.Anchored = false
				ShockClone.CanCollide = false
				ShockClone.Size = Vector3.new(1,1,1)
				ShockClone.Position = Char:FindFirstChild("Right Arm").Position + Vector3.new(0,0,-2)
				ShockTween2:Play()
				ShockTween:Play()
			end)
		end
		
		
		
		Track.Ended:Connect(function()
			task.wait(1)
			db = false
		end)
	end)
	
end

return module

—local----

local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local Hum = Char:FindFirstChild("Humanoid") or Char:WaitForChild("Humanoid")
local IceDaggerModule = require(script.Ice_Barrage_Framework)

plr.CharacterAdded:Connect(function(Char)
	IceDaggerModule:Activate(Char,plr,Hum)
end)

The problem is that it just does activate now

Try removing if gpe then return end

I’ve not used :Once() before, looks a little sus. Could that have something to do with it running once?

Or maybe the debounce is never set to false. 3 things to test here.

Sorry it took a while to respond but no of these things are the fix

Hmmm, did you find a solution yet?

No unfortunately, random question have you made anything like this that you could show

No, and are you sure you’ve tried removing GPE, trying something else instead of :Once() and you’ve check that the debounce is truly set to false, or even tried to remove the debounce?

removing the gpe wont do anything do you know what a gameprocessedevent is

Yes but I was just looking into whatever could bug it out.
Have you tried putting the script inside StarterGui?

Which event? Are you referring to the InputBegan connection, because that’s obviously wrong since contents inside StarterPlayerScripts cloned upon the Player joining once and doesn’t reset, so I don’t know where you are getting your information from.

GPE is irrelevant here.


The immediate problem that screams out to me is your other LocalScript, send the code for that one. You are passing a Humanoid which most likely indicate the issue since that variable can be the old Humanoid based on the error you are describing. The solution to simply send just the Player over and getting the new Character and Humanoid whenever you call Activate, or better yet, don’t pass anything since LocalPlayer will exist in the local context anyways.

1 Like