What do you want to achieve? Keep it simple and clear!
Alright, so I was making a script that checks if a key is being pressed and it will print all the name of the parts in a folder every second.
What is the issue? Include screenshots / videos if possible!
the issue is that when the key I is being pressed there is nothing in the output but when I type the key in the Chat bar it starts printing the parts in the folder. I have no clue how. I don’t have any Chatted Events in the script. I might have just discovered a bug or something.
Script is a LocalScript
Located in StarterCharacterScripts
local Phase = game.Workspace:WaitForChild("Phase")
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.I then
print("Letter I has been pressed!")
for _,v in pairs(Phase:GetChildren()) do
wait(1)
print(v)
end
end
end)
I think the issue has to do with the Character part, but I see a few issues you could fix.
I think the script is infinitely waiting for the Character to be added, but once it does a new script gets added.
Instead just do
local Character = script.Parent
You can replace game.Workspace with workspace
Replace game.Players with game:GetService("Players")
Add a parameter called gameProcessedEvent and return if the parameter is true:
if gameProcessedEvent then return end
The script would look like this:
local UserInputService = game:GetService("UserInputService")
local LocalPlayer = game:GetService("Players").LocalPlayer
local Character = script.Parent --or LocalPlayer.Character
local Phase = workspace:WaitForChild("Phase")
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return end
if input.KeyCode == Enum.KeyCode.I then
print("Letter I has been pressed!")
for _,v in pairs(Phase:GetChildren()) do
wait(1)
print(v)
end
end
end)
Edit: @Abcreator is right I forgot about this feature.