User Input Service only works before dying

My script only fires UserInputService before dying

spawnTracker.OnClientEvent:Connect(function() ← The script checks when the player spawns and this part works fine

print(“Spawned”)
if Stand.Value == “The Hand” then

  print("Passed Check") <-- **The Script passes the If then statement after dying**

  UIS.InputBegan:Connect(function(input, isTyping) <-- The Event doesn't fire
  	print("Fire Function") <-- This doesn't show in the output after dying
  	ZaHando(input, isTyping)
  end)	

end
end)

Formatted version of the script so anyone else trying to solve it can read it smh

spawnTracker.OnClientEvent:Connect(function()
    print(“Spawned”)
    if Stand.Value == “The Hand” then
        print("Passed Check")  -- The Script passes the If then statement after dying
        UIS.InputBegan:Connect(function(input, isTyping)
            print("Fire Function") -- This doesn't show in the output after dying
  	        ZaHando(input, isTyping)
        end)
    end
end)
1 Like

My bad I just split it into parts

Well, whats the script that fires the remote event, maybe thats the issue.

btw the script contains OnClientEvent meaning it is a server script, but then attempts to use input began??? use UIS in a localscript it wont work on the server

2 Likes

local Players = game:GetService(“Players”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)

local spawnTracker = ReplicatedStorage:WaitForChild(“RemoteEvents”):WaitForChild(“PlayerSpawned”)

Players.PlayerAdded:Connect(function(Player)

Player.CharacterAdded:Connect(function(Character)

  Character.Humanoid.Died:Connect(function()
  	print("Spawning . . .")
  	wait(5)
  	
  	spawnTracker:FireClient(Player)
  	Player:LoadCharacter()
  end)

end)

spawnTracker:FireClient(Player)
Player:LoadCharacter()

end)

Character Auto Loads is disabled

Thx for the script, but I’d recommend you click on the </> button to format a script:
image

1 Like

format your scripts correctly
put your code inside 3 of these symbols ```

print("joe")

image

1 Like

Oh for some reason it works regardless

Also, Player.CharacterAdded, fires when a player respawns/spawns in. Dont do player.Character.Humanoid.Died. Player.CharacterAdded already does that for you.

I’m assuming this script is a local script, which is placed in StarterPlayerScripts.

When a player spawns, all scripts located in StarterPlayerScripts resets. If you want to fix this issue, you can make a variable and set the value to true whenever the Remote is fired.

local Enabled = false

spawnTracker.OnClientEvent:Connect(function()
	if Stand.Value == “The Hand” then
		Enabled = true
	end
end)

UIS.InputBegan:Connect(function(input, isTyping)
	if Enabled then
		print("Fire Function")
		ZaHando(input, isTyping)
	end
end)

Humanoid.Died works better for this

Well the script works fine for me, I think its an issue with your if statements, mind putting the full local script?

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

if not Character or not Character.Parent then
	Character = Player.CharacterAdded:wait()
end

local UIS = game:GetService("UserInputService")
local rp = game:GetService("ReplicatedStorage")

local theHand = rp:WaitForChild("RemoteEvents"):WaitForChild("The Hand")
local spawnTracker = rp:WaitForChild("RemoteEvents"):WaitForChild("PlayerSpawned")

local Active = script.Parent.Parent.Parent
local debounce = false

local Stand = Player:WaitForChild("Stand")
local thCheck = false

local inputControl

local function ZaHando(input, isTyping)	
	print("Input Sent")
	if Stand.Value == "The Hand" and Active:GetAttribute("Active") == false then
		print("Input Valid")
		local CharacterStand = Character:FindFirstChild("The Hand", true)
		if CharacterStand then
			print("The Hand Found")
			if isTyping then
				return
			elseif input.KeyCode == Enum.KeyCode.E then
				if not debounce then
					debounce = true

					Active:SetAttribute("Active", true)
					theHand:FireServer("E")
				end	

			elseif input.KeyCode == Enum.KeyCode.F then
				if not debounce then
					debounce = true

					Active:SetAttribute("Active", true)
					theHand:FireServer("F")
				end	

			elseif input.KeyCode == Enum.KeyCode.R then
				if not debounce then
					debounce = true

					Active:SetAttribute("Active", true)
					theHand:FireServer("R")
				end	

			elseif input.KeyCode == Enum.KeyCode.T then
				if not debounce then
					debounce = true

					Active:SetAttribute("Active", true)
					theHand:FireServer("T")
				end	

			elseif input.KeyCode == Enum.KeyCode.Y then
				if not debounce then
					debounce = true

					Active:SetAttribute("Active", true)
					theHand:FireServer("Y")
				end	
			end			
		end
	end
end

spawnTracker.OnClientEvent:Connect(function()
	print("Spawned")
	if Stand.Value == "The Hand" then
		print("Passed Check")

		UIS.InputBegan:Connect(function(input, isTyping)
			print("Fire Function")
			ZaHando(input, isTyping)
		end)	
	end	
end)

Character:WaitForChild("Humanoid").Died:Connect(function()
	print("rip")
end)

theHand.OnClientEvent:Connect(function()
	Active:SetAttribute("Active", false)
	debounce = false
end)
1 Like

Try seeing what the stand value is printing, maybe that could be the issue.

Does this also apply to starter pack because that is where the script is placed

have you written this in a local scriot?

I have written this in a local script

Starter pack allows for local script. Since starter pack replicates to the player. Tho I’d recommend you put it in starter player scripts.

The value is right, no problems there