-- Located in StarterPlayerScripts
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local function OnCharacterAdded(Character)
local function OnInputBegan(Input, Chat)
print("I won't reconnect a new thread again when Character respawns! Hopefully")
end
UserInputService.InputBegan:Connect(OnInputBegan)
end
Player.CharacterAdded:Connect(OnCharacterAdded)
Does anyone know? Just want to not cause a performance issue.
Yes it will, since it’s making a new connection each time the character spawns and isn’t disconnecting it.
Just move the connection stuff outside
-- Located in StarterPlayerScripts
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local function OnInputBegan(Input, Chat)
print("I won't reconnect a new thread again when Character respawns! Hopefully")
end
UserInputService.InputBegan:Connect(OnInputBegan)
OR you can disconnect the old connection, but I don’t really recommend this as it is unnecessary
Alternative
-- Located in StarterPlayerScripts
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Connection = nil
local function OnCharacterAdded(Character)
if Connection then
Connection:Disconnect()
end
local function OnInputBegan(Input, Chat)
print("I won't reconnect a new thread again when Character respawns! Hopefully")
end
Connection = UserInputService.InputBegan:Connect(OnInputBegan)
end
Player.CharacterAdded:Connect(OnCharacterAdded)